pi.base2009-01-06 09:23:30
Summary
pi.base creates javascript classes by given prototype and constructor.It provides creating private members and clonning hash and array values in the prototype.Also, It generates getter/setter functions for private members automatically.
Syntax
var className = new pi.base;
className.init = function(value){
this.setPrivateMember(value);
};
className.body = {
propertyName:value,
_privateMember:value
};
className = className.build();
General Usage
>>> var product = new pi.base;
>>> product.init = function(_name,_price){
this.environment.setName(_name).environment.setPrice(_price);
};
>>> product.body = {
"sell":function(){
//
},
"remove":function(){
//
},
"environment":{
"_name":"", "_price":"0$",
"setPrice":function(_value){
this._setPrice(_value+"$"); // If you set a getter/setter method, pi will automatically add underscore to the beginning of the name.
}
}
};
>>> product = product.build();
>>> var bicycle = new product("bmx",1500);
>>> bicycle.environment.getPrice();
"1500$"
>>> bicycle.environment._price;
null
Properties
body
pi.base.body = { memberName:memberValue, _PrivateMemberName:propertyValue };
Prototype of the class will be created.
init
pi.base.build();
Constructor of the class will be created.
Methods
build
pi.base.build();
Creates and returns the class.