Monster = MVC.Class.extend('monster',
/* @static *|
{
count: 0
},
/* @prototype *|
{
init : function(name){
this.name = name;
this.Class.count++
}
})
hydra = new Monster('hydra')
dragon = new Monster('dragon')
hydra.name // -> hydra
Monster.count // -> 2
Monster.className // -> 'monster' Notice that the prototype init function is called when a new instance of Monster is created.
First = MVC.Class.extend(
{
static_method : function(){ return 1;}
},{})
Second = First.extend({
static_method : function(){ return this._super()+1;}
},{})
Second.static_method() // -> 2 MVC.Doc.Directive.Author = MVC.Class.extend('author'); you tell the documentation engine to look for @author and whatever comes after it as this.author.
className is saved as a static property. You can access it from instance methods like:
this.Class.className MyClass = MVC.Class.extend(
{
init: function(){} //static constructor
},
{
init: function(){} //prototype constructor
}) The static init constructor is called after
a class has been created, but before extended is called on its base class.
This is a good place to add introspection and similar class setup code.
The prototype callback is called whenever a new instance of the class is created.
new MVC.Class() -> mvc.class
Creating a new instance of an object that has extended MVC.Class calls the init prototype function and returns a new instance of the class.
The name of the class provided for introspection purposes.
extend(className, klass, proto) -> MVC.Class
{String} - the classes name (used for classes w/ introspection)
{Object} - the new classes static/class functions
{Object} - the new classes prototype functions
{MVC.Class} - returns the new class
extended(Class) -> undefined
{MVC.Class} - the extending class.
Access to the static properties of the instance's class.
init() -> undefined