My Object Oriented javascript.
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 |
| 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. |
| Utility Functions | |
| Functions | |
| $type | Returns the type of object that matches the element passed in. |
| $merge | merges a number of objects recursively without referencing them or their sub-objects. |
| $extend | Copies all the properties from the second passed object to the first passed Object. |
| $native | Will add a .extend method to the objects passed as a parameter, but the property passed in will be copied to the object’s prototype only if non previously existent. |
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 |
| 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. |
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 20Implements 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 | |
| $type | Returns the type of object that matches the element passed in. |
| $merge | merges a number of objects recursively without referencing them or their sub-objects. |
| $extend | Copies all the properties from the second passed object to the first passed Object. |
| $native | Will add a .extend method to the objects passed as a parameter, but the property passed in will be copied to the object’s prototype only if non previously existent. |
function $type( obj )
Returns the type of object that matches the element passed in.
| obj | the object to inspect. |
var myString = 'hello';
$type(myString); //returns "string"
| ’element’ | if obj is a DOM element node |
| ’textnode’ | if obj is a DOM text node |
| ’whitespace’ | if obj is a DOM whitespace node |
| ’array’ | if obj is an array |
| ’object’ | if obj is an object |
| ’string’ | if obj is a string |
| ’number’ | if obj is a number |
| ’boolean’ | if obj is a boolean |
| ’function’ | if obj is a function |
| false | (boolean) if the object is not defined or none of the above. |
function $merge()
merges a number of objects recursively without referencing them or their sub-objects.
any number of objects.
var $extend = Object.extend = function()
Copies all the properties from the second passed object to the first passed Object. If you do myWhatever.extend = $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'
};
$extend(firstOb, secondOb);
//firstOb will become:
{
'name': 'John',
'lastName': 'Dorian',
'age': '20',
'sex': 'male'
};The first object, extended.
var $native = Object.Native = function()
Will add a .extend method to the objects passed as a parameter, but the property passed in will be copied to the object’s prototype only if non previously existent. Its handy if you dont want the .extend method of an object to overwrite existing methods. Used automatically in mootools to implement Array/String/Function/Number methods to browser that dont support them whitout manual checking.
a number of classes/native javascript objects
Returns the type of object that matches the element passed in.
function $type( obj )
merges a number of objects recursively without referencing them or their sub-objects.
function $merge()
Copies all the properties from the second passed object to the first passed Object.
var $extend = Object.extend = function()
Will add a .extend method to the objects passed as a parameter, but the property passed in will be copied to the object’s prototype only if non previously existent.
var $native = Object.Native = function()