Object.create によるオブジェクトの継承について質問があります。
インターフェイスのように動作する必要がある 2 つのオブジェクトがあります。Object3DとLight。Object3D3D 空間で実際のオブジェクトを表示します。空間内の位置があり、たとえばこの位置を変更する機能が必要です。Light光るものすべてです。そして、すべての光にはそれぞれの色があります。
// I have resons to use iif, dont bother with that ;)
var Object3D = (function() {
var Object3D = function() {
this.position = vec3.create();
};
return Object3D;
})();
var Light = (function() {
var Light = function() {
this.color = new Array(4);
};
return Light;
})();
ここで、「クラス」となる 2 つの別のオブジェクトが必要です。一つ目はAmbientLight。AmbientLightどこでも光るだけなので、位置はありません。したがって、 から継承しLightます。もう一つはPointLight. PointLightですがLight、どこでも光るわけではないので、位置もあります。ある程度の範囲があります。したがって、 からも継承する必要がありObject3Dます。どうすればいいですか?Object.create からの結果をマージできますか?
var AmbientLight = (function() {
var AmbientLight = function() {
Light.call(this);
};
AmbientLight.prototype = Object.create(Light.prototype);
return AmbientLight;
})();
var PointLight = (function() {
var PointLight = function() {
Light.call(this);
Object3D.call(this);
this.range = 10.0;
};
// this isnt correct
// how to make it correct?
PointLight.prototype = Object.create(Light.prototype);
PointLight.prototype = Object.create(Object3D.prototype);
return PointLight;
})();