Moo.js

My Object Oriented javascript.

Author

Valerio Proietti, http://mad4milk.net

License

MIT-style license.

Mootools Credits

Summary
Moo.jsMy Object Oriented javascript.
ClassThe base class object of the http://mootools.net framework.
Properties
emptyReturns an empty function
extendReturns the copy of the Class extended with the passed in properties.
implementImplements the passed in properties to the base Class prototypes, altering the base class, unlike Class.extend.
Utility Functions
Functions
$typeReturns the type of object that matches the element passed in.
$mergemerges a number of objects recursively without referencing them or their sub-objects.
$extendCopies all the properties from the second passed object to the first passed Object.
$nativeWill 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.

Class

The base class object of the http://mootools.net framework.

Arguments

propertiesthe collection of properties that apply to the class.  Creates a new class, its initialize method will fire upon class instantiation.

Example

var Cat = new Class({
initialize: function(name){
this.name = name;
}
});
var myCat = new Cat('Micia');
alert(myCat.name); //alerts 'Micia'
Summary
Properties
emptyReturns an empty function
extendReturns the copy of the Class extended with the passed in properties.
implementImplements the passed in properties to the base Class prototypes, altering the base class, unlike Class.extend.

Properties

empty

Returns an empty function

extend

Returns the copy of the Class extended with the passed in properties.

Arguments

propertiesthe properties to add to the base class in this new Class.

Example

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

implement

Implements the passed in properties to the base Class prototypes, altering the base class, unlike Class.extend.

Arguments

propertiesthe properties to add to the base class.

Example

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'

Utility Functions

Summary
Functions
$typeReturns the type of object that matches the element passed in.
$mergemerges a number of objects recursively without referencing them or their sub-objects.
$extendCopies all the properties from the second passed object to the first passed Object.
$nativeWill 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.

Functions

$type

function $type(obj)

Returns the type of object that matches the element passed in.

Arguments

objthe object to inspect.

Example

var myString = 'hello';
$type(myString); //returns "string"

Returns

’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.

$merge

function $merge()

merges a number of objects recursively without referencing them or their sub-objects.

Arguments

any number of objects.

$extend

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.

Example

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'
};

Returns

The first object, extended.

$native

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.

Arguments

a number of classes/native javascript objects

Returns the copy of the Class extended with the passed in properties.
function $type(obj)
Returns the type of object that matches the element passed in.
function $merge()
merges a number of objects recursively without referencing them or their sub-objects.
var $extend = Object.extend = function()
Copies all the properties from the second passed object to the first passed Object.
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.