// The following is the method used by OOP
// This is very convenient It's obscene...because JS is not an OOP language...
// But the great fans guide us to do this
// Belldandy will bless those who use these methods to OOP...
Function.prototype .inherits = function(base){
//Derivation relationship, prototype is retained
//Only single derivation is supported
this.prototype = new base();
return this;
}
Function.prototype.create = function(){
//The creator of the class is equivalent to using new
//JS does not support the use of call and apply in the constructor, so...
/ /Belldandy, thank you for telling me how to solve this problem...
var _args = [];
for(i=0;i
return eval('new this(' _args.join(',') ')'); //eval is used...Bell, please be nicer next time My idea...
}
Function.prototype.pin = function(pinner,args){
// Register service, or "pin" service
// EventManager can do this
// You can also think of it as implementing an interface with a default implementation...
// For example, pin EventManager can be like this: Class.pin(core.WvwntManager)
args = args || [ ];
pinner.apply(this.prototype,args);
return this;
}
Function.prototype.method = function(name, f) { //Add method, efficient
if (!(f instanceof Function)) throw new Error('Invalid method binding, got type ' typeof f '; expected function');
this.prototype[name] = f;
return this
}
Function.prototype.property = function(name, localName, getter, setter) { //Add properties, you can customize getters and setters
if (!name || !name instanceof String) throw new EnvironmentException('When defining the attribute, the attribute name is not defined or is not a string');
if (!localName || !localName instanceof String) localName = '_local_' name;
if(getter instanceof Function) {
this.prototype['_belldandy_get_' name] = getter;
}
if(setter instanceof Function){
this.prototype['_belldandy_set_' name] = setter;
}
this.prototype[name] = new Function("value , force","
if (!value && !force) {
if (!this['" '_belldandy_get_' name "'] || !this['" '_belldandy_get_' name "'] instanceof Function)
return this['" localName "']; /* when no getter is set*/
else
return this['" '_belldandy_get_ ' name "'].call(this);
} else {
if (!this['" '_belldandy_set_' name "'] || !this['" '_belldandy_set_' name "'] instanceof Function )
this['" localName "'] = value;
else
this['" '_belldandy_set_' name "'].call(this, value);
return this
} ") //Belldandy, forgive me, although this does not produce a closure
return this;
}
Function.prototype.static = function(name,value){ //Static features, including attributes And the method
this[name] = value;
return this;
}