1
var util = require('util');
function Entity(){
//this.x == 10 at this point
this.x = 0;
this.y = 0;
this.globalInit();
}
Entity.prototyp.globalInit = function(){
console.log("this.x ", x);
};
function Actor(){
this.x = 10;
this.y = 10;
Actor.super_.apply(this, arguments);
}
util.inherits(Entity, Actor);
var a = new Actor();
//outputs -> this.x 0
我有这两个构造函数。我想要在子构造函数中定义的属性是最终的属性。我可以将Actor.super_.apply
移动到构造函数的顶部,但有一个初始化逻辑(globalInit
),我想保留在父构造函数的末尾node.js继承优先子构造函数属性