Core contains an handful of common sense functions used in MooTools.
Returns true if a value is undefined.
nil(obj);
function myFunction(arg){ if(nil(arg)) alert('The object is null or undefined.'); else alert('The object is defined.'); }
This method is equivalent to $defined from MooTools 1.2, but opposite.
Returns the type of object that matches the item passed in.
typeOf(obj);
var myString = 'hello'; typeOf(myString); //Returns "string".
This method is equivalent to $type from MooTools 1.2.
Checks to see if an object is an instance of a particular Type.
instanceOf(item, object)
var foo = []; instanceOf(foo, Array) // true instanceOf(foo, String) // false var myClass = new Class(); var bar = new myClass(); instanceOf(bar, myClass) // true
Used to iterate through an object.
Object.each(obj, fn[, bind]);
fn(item, index, object)
//Alerts "The first day of the week is Sunday", "The second day of the week is Monday", etc: Object.each({first: "Sunday", second: "Monday", third: "Tuesday"}, function(value, key){ alert("The " + key + " day of the week is " + value); });
This method is an object-specific equivalent of $each from MooTools 1.2.
Merges any number of objects recursively without referencing them or their sub-objects.
var merged = Object.merge(obj1, obj2[, obj3[, ...]]);
var obj1 = {a: 0, b: 1}; var obj2 = {c: 2, d: 3}; var obj3 = {a: 4, d: 5}; var merged = Object.merge(obj1, obj2, obj3); //returns {a: 4, b: 1, c: 2, d: 5}, (obj1, obj2, and obj3 are unaltered) var nestedObj1 = {a: {b: 1, c: 1}}; var nestedObj2 = {a: {b: 2}}; var nested = Object.merge(nestedObj1, nestedObj2); //returns: {a: {b: 2, c: 1}}
Returns a copy of an object.
var clone = Object.clone(obj);
var obj1 = {a: 0, b: 1}; var obj2 = Object.clone(obj1); obj1.a = 42; alert(obj1.a); // alerts '42' alert(obj2.a); // alerts '0'
This is an object-specific equivalent of $unlink from MooTools 1.2.
Copies all the properties from the second object passed in to the first object passed in.
Object.append(original, extension);
var firstObj = { 'name': 'John', 'lastName': 'Doe' }; var secondObj = { 'age': '20', 'sex': 'male', 'lastName': 'Dorian' }; Object.append(firstObj, secondObj); //firstObj is now: {'name': 'John', 'lastName': 'Dorian', 'age': '20', 'sex': 'male'};
This method has been deprecated and will have no equivalent in MooTools 2.0.
If you really need this function you can implement it like so:
var $chk = function(obj){ return !!(obj || obj === 0); };
This method has been deprecated. Please use Function:clear instead.
This method has been deprecated. Please use nil instead.
This method has been deprecated and will have no equivalent in MooTools 2.0.
If you really need this function you can implement it like so:
var $arguments = function(i){ return function(){ return arguments[i]; }; };
This method has been deprecated. Use Function.from instead.
var myFunc = Function.from(); // Or probably better.... var myFunc = function(){};
This method has been deprecated. Use Function.from instead.
myLink.addEvent('click', Function.from(false)); //Prevents a link Element from being clickable.
This method has been deprecated. Please use Object.append instead.
This method has been deprecated. Please use Object.merge instead.
This method has been deprecated. Please use Array.each or Object.each instead.
This method has been deprecated. Please use Array.pick instead.
This method has been deprecated. Please use Number.random instead.
This method has been deprecated. Please use Array.from instead.
This method has been deprecated. Please use Date.now() instead.
var time = Date.now();
This method has been deprecated. Please use Function.stab instead.
This method has been deprecated. Please use typeOf instead.
This documentation is released under a Attribution-NonCommercial-ShareAlike 3.0 License.