我聽(tīng)說(shuō)是同級(jí)對(duì)比但是通過(guò)代碼如何實(shí)現(xiàn)比如舊js對(duì)象{'div','class=a',{children}}新js對(duì)象{'div','class=b',{children}}js對(duì)象與js對(duì)象對(duì)比1.我想知道底層是通過(guò)什么方法(代碼)對(duì)比是遍歷嗎?2.找到了不同處后面的子節(jié)點(diǎn)都不再對(duì)比了嗎?直接刪除后面重新生成?
2 回答

慕虎7371278
TA貢獻(xiàn)1802條經(jīng)驗(yàn) 獲得超4個(gè)贊
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 了解一下
- 2 回答
- 0 關(guān)注
- 719 瀏覽
添加回答
舉報(bào)
0/150
提交
取消