亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

react虛擬dom中舊js對象是如何跟新js對象進行對比(代碼層面)如何實現

react虛擬dom中舊js對象是如何跟新js對象進行對比(代碼層面)如何實現

繁花不似錦 2019-02-19 16:25:43
我聽說是同級對比但是通過代碼如何實現比如舊js對象{'div','class=a',{children}}新js對象{'div','class=b',{children}}js對象與js對象對比1.我想知道底層是通過什么方法(代碼)對比是遍歷嗎?2.找到了不同處后面的子節點都不再對比了嗎?直接刪除后面重新生成?
查看完整描述

2 回答

?
慕虎7371278

TA貢獻1802條經驗 獲得超4個贊

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 了解一下


查看完整回答
反對 回復 2019-02-19
  • 2 回答
  • 0 關注
  • 714 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號