【发布时间】:2015-10-02 01:22:46
【问题描述】:
也许你会发现问题。控制台总是说:
TypeError:this._init 不是函数。 (在 'this._init()' 中,'this._init' 是未定义的)
nodes = [];
for (var i = 0; i < 3; i++) {
var newNode = new Node(i*100,0);
nodes.push(newNode);
};
function Node(posX, posY, parent) {
if (typeof parent === 'undefined') { parent = 0; }
this.parent = parent;
this.children = [];
this.text = "Node";
this.posX = posX;
this.posY = posY;
this._init();
this._init = function() {
alert("test");
}
}
【问题讨论】:
-
为什么应该是函数?您在尝试调用它之后定义它。函数表达式没有被提升。
标签: javascript class oop typeerror