Like you all know a button is a button... click, up, down, do this, do that. So I wrote some default button behavior "class/object".
external default button.js:
function Button(parent) {
var self = this;
this.enabled = true;
this.visible = true;
...
this.initialized = false;
f_createButton(parent, self);
this.initialized = true;
...
}
Button.prototype = {
get initialized () {
return this._initialized;
},
set initialized(bool){
this._initialized = bool
if(this.initialized === true) {
... do default stuff
}
},
get enabled(){
return this._enabled;
},
set enabled(bool){
this._enabled = bool;
if(document.getElementById(this.id)) { // is button defined?
var mClassName = document.getElementById(this.id).children[0].className;
document.getElementById(this.id).className = (this.enabled === false) ? "button button-Gray_disabled" : "button button-" + this.defaultStyle;
document.getElementById(this.id).children[0].className = (this.enabled === false) ? mClassName + "_disabled" : mClassName.replace("_disabled","");
}
}
}
function f_createButton("", obj) {
.... create DOM element
}
include button.js in html & extend Button "Class/Object":
Object.defineProperty(Button.prototype,"buttonStyle", {
get : function() {
return this._buttonStyle;
},
set : function(str) {
this._buttonStyle = str;
if(this.id !== "undefined" && document.getElementById(this.id)) { // is button defined?
document.getElementById(this.id).style.backgroundImage = 'url(Images/'+this.buttonStyle+'/buttons.png)';
}
}
});
This almost works, but it kills the original Button initialized.
Object.defineProperty(Button.prototype,"initialized", {
set : function( bool ) {
this._initialized = bool;
if(this.initialized === true) {
this.buttonStyle = "NONE";
}
}
});
How can I extend the original setter?