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繼承優先子構造函數屬性