class VNode {
constructor(tag, data, children, text, ele) {
this.tag = tag
this.data = data
this.children = children
this.text = text
this.ele = ele
}
}
function createEmptyVNode() {
const node = new VNode()
node.text = ''
return node
}
function createTextNode(val) {
const node = new VNode()
node.text = String(val)
return node
}
function cloneVNode(node) {
const cloneNode = new VNode(node.tag, node.data, node.children, node.text, node.ele)
return cloneNode
}
function render () {
return new VNode(
'span',
{
/* 指令集合数组 */
directives: [
{
/* v-show指令 */
rawName: 'v-show',
expression: 'isShow',
name: 'show',
value: true
}
],
/* 静态class */
staticClass: 'demo'
},
[
createTextNode("Text1"),
createTextNode("Text2"),
]
)
}
const v1 = render()
console.dir("v1: ", v1)
const v2 = cloneVNode(v1)
console.log("v2: ", v2)
console.log("v1 === v2 ? ", v1 === v2)
console