My Object Oriented javascript.
Has no dependancies.
Valerio Proietti, http://mad4milk.net
MIT-style license.
Moo.js | My Object Oriented javascript. |
Class | The base class object of the http://mootools.net framework. |
Properties | |
empty | Returns an empty function |
create | same as new Class. |
extend | Returns the copy of the Class extended with the passed in properties. |
implement | Implements the passed in properties to the base Class prototypes, altering the base class, unlike Class.extend. |
Object related Functions | |
Functions | |
Object. extend | Copies all the properties from the second passed object to the first passed Object. |
Object. Native | Will add a .extend method to the objects passed as a parameter, equivalent to Class.implement |
The base class object of the http://mootools.net framework.
properties | the collection of properties that apply to the class. Creates a new class, its initialize method will fire upon class instantiation. |
var Cat = new Class({
initialize: function(name){
this.name = name;
}
});
var myCat = new Cat('Micia');
alert myCat.name; //alerts 'Micia'
Properties | |
empty | Returns an empty function |
create | same as new Class. |
extend | Returns the copy of the Class extended with the passed in properties. |
implement | Implements the passed in properties to the base Class prototypes, altering the base class, unlike Class.extend. |
same as new Class. see Class
Returns the copy of the Class extended with the passed in properties.
properties | the properties to add to the base class in this new Class. |
var Animal = new Class({
initialize: function(age){
this.age = age;
}
});
var Cat = Animal.extend({
initialize: function(name, age){
this.parent(age); //will call the previous initialize;
this.name = name;
}
});
var myCat = new Cat('Micia', 20);
alert myCat.name; //alerts 'Micia'
alert myCat.age; //alerts 20
Implements the passed in properties to the base Class prototypes, altering the base class, unlike Class.extend.
properties | the properties to add to the base class. |
var Animal = new Class({
initialize: function(age){
this.age = age;
}
});
Animal.implement({
setName: function(name){
this.name = name
}
});
var myAnimal = new Animal(20);
myAnimal.setName('Micia');
alert(myAnimal.name); //alerts 'Micia'
Functions | |
Object. extend | Copies all the properties from the second passed object to the first passed Object. |
Object. Native | Will add a .extend method to the objects passed as a parameter, equivalent to Class.implement |
Object.extend = function()
Copies all the properties from the second passed object to the first passed Object. If you do myWhatever.extend = Object.extend the first parameter will become myWhatever, and your extend function will only need one parameter.
var firstOb = {
'name': 'John',
'lastName': 'Doe'
};
var secondOb = {
'age': '20',
'sex': 'male',
'lastName': 'Dorian'
};
Object.extend(firstOb, secondOb);
//firstOb will become:
{
'name': 'John',
'lastName': 'Dorian',
'age': '20',
'sex': 'male'
};
The first object, extended.
Object.Native = function()
Will add a .extend method to the objects passed as a parameter, equivalent to Class.implement
a number of classes/native javascript objects
Copies all the properties from the second passed object to the first passed Object.
Object.extend = function()
Object.Native = function()