I want to call setter “transform” in the superclass SceneNode from the overriden setter in the subclass Camera.
The classes look like this:
SceneNode:
function SceneNode(){
this._transform = M4x4.I;
}
SceneNode.prototype.__defineSetter__("transform",
function(transform){
this._transform = transform;
}
);
SceneNode.prototype.__defineGetter__("transform",
function(){
return this._transform;
}
);
Camera:
function Camera(){
}
Camera.prototype = new SceneNode();
Camera.base = SceneNode.prototype;
Camera.prototype.__defineSetter__("transform",
function(transform){
Camera.base.transform.call(this, transform);
this.updateViewMatrix();
}
);
Camera.prototype.__defineGetter__("transform",
function(){
return this._transform;
}
);
This does not work because “Camera.base.transform” is not defined according to firefox. I used to call “Camera.base.setTransform.call(this, transform);” before, which worked, but since I learned about setters and getters, I tried to get rid of setXXX functions.
Getters and setters hide the underlying function, so you need a way to bypass the property and obtain the setter directly. (It’s undefined because it’s actually accessing the return value of
SceneNode.prototype‘s getter, which has no instance to get a value from.) The counterpart to__defineSetter__is__lookupSetter__:But those methods are deprecated, so the correct (ECMAScript 5) way is to use
Object.definePropertyandObject.getOwnPropertyDescriptor: