mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-20 23:52:40 +08:00
e3e1db619f
* Revert "move in port/native to platforms/native (#7962)"
This reverts commit 96871ba26b.
* move port/native into platforms/native
50 lines
963 B
JavaScript
Executable File
50 lines
963 B
JavaScript
Executable File
const EventTarget = require('./EventTarget');
|
|
|
|
class Node extends EventTarget {
|
|
constructor() {
|
|
super()
|
|
this.childNodes = []
|
|
this.parentNode = window.__canvas;
|
|
}
|
|
|
|
appendChild(node) {
|
|
if (node instanceof Node) {
|
|
this.childNodes.push(node)
|
|
} else {
|
|
throw new TypeError('Failed to executed \'appendChild\' on \'Node\': parameter 1 is not of type \'Node\'.')
|
|
}
|
|
}
|
|
|
|
insertBefore(newNode, referenceNode) {
|
|
//REFINE:
|
|
return newNode;
|
|
}
|
|
|
|
replaceChild(newChild, oldChild) {
|
|
//REFINE:
|
|
return oldChild;
|
|
}
|
|
|
|
cloneNode() {
|
|
const copyNode = Object.create(this)
|
|
|
|
Object.assign(copyNode, this)
|
|
return copyNode
|
|
}
|
|
|
|
removeChild(node) {
|
|
const index = this.childNodes.findIndex((child) => child === node)
|
|
|
|
if (index > -1) {
|
|
return this.childNodes.splice(index, 1)
|
|
}
|
|
return null
|
|
}
|
|
|
|
contains(node) {
|
|
return this.childNodes.indexOf(node) > -1;
|
|
}
|
|
}
|
|
|
|
module.exports = Node;
|