我聽說是同級對比但是通過代碼如何實現比如舊js對象{'div','class=a',{children}}新js對象{'div','class=b',{children}}js對象與js對象對比1.我想知道底層是通過什么方法(代碼)對比是遍歷嗎?2.找到了不同處后面的子節點都不再對比了嗎?直接刪除后面重新生成?
1 回答

慕碼人2483693
TA貢獻1860條經驗 獲得超9個贊
class VNode { constructor (tagName, props, children) { this.tagName = tagName this.props = props this.children = children } render () { const { props, children } = this, dom = document.createElement(this.tagName) Object.entries(props).map(([key, value]) => dom.setAttribute(key, value)) children.map(o => dom.appendChild(o instanceof VNode ? o.render() : document.createTextNode(o))) return dom } }const h = (tagName, props, children) => new VNode(tagName, props, children)
react的createClass 了解一下
添加回答
舉報
0/150
提交
取消