Core.js

MootoolsMy Object Oriented javascript.

License

MIT-style license.

MooTools Copyright

copyright © 2007 Valerio Proietti, https://github.com/kamicane

MooTools Credits

Summary
Core.js
Core Functions
Functions
$definedReturns true if the passed in value/object is defined, that means is not null or undefined.
$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.
$chkReturns true if the passed in value/object exists or is 0, otherwise returns false.
$pickReturns the first object if defined, otherwise returns the second.
$randomReturns a random integer number between the two passed in values.
$timeReturns the current timestamp
$clearclears a timeout or an Interval.
AbstractAbstract class, to be used as singleton.
windowSome properties are attached to the window object by the browser detection.

Core Functions

Summary
Functions
$definedReturns true if the passed in value/object is defined, that means is not null or undefined.
$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.
$chkReturns true if the passed in value/object exists or is 0, otherwise returns false.
$pickReturns the first object if defined, otherwise returns the second.
$randomReturns a random integer number between the two passed in values.
$timeReturns the current timestamp
$clearclears a timeout or an Interval.

Functions

$defined

Returns true if the passed in value/object is defined, that means is not null or undefined.

Arguments

objobject to inspect

$type

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
’arguments’if obj is an arguments object
’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
’regexp’if obj is a regular expression
’class’if obj is a Class.  (created with new Class, or the extend of another class).
’collection’if obj is a native htmlelements collection, such as childNodes, getElementsByTagName .. etc.
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.

Example

var mergedObj = $merge(obj1, obj2, obj3);
//obj1, obj2, and obj3 are unaltered

$extend

var $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 = 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

$chk

Returns true if the passed in value/object exists or is 0, otherwise returns false.  Useful to accept zeroes.

Arguments

objobject to inspect

$pick

Returns the first object if defined, otherwise returns the second.

Arguments

objobject to test
pickedthe default to return

Example

function say(msg){
    alert($pick(msg, 'no meessage supplied'));
}

$random

Returns a random integer number between the two passed in values.

Arguments

mininteger, the minimum value (inclusive).
maxinteger, the maximum value (inclusive).

Returns

a random integer between min and max.

$time

function $time()

Returns the current timestamp

Returns

a timestamp integer.

$clear

clears a timeout or an Interval.

Returns

null

Arguments

timerthe setInterval or setTimeout to clear.

Example

var myTimer = myFunction.delay(5000); //wait 5 seconds and execute my function.
myTimer = $clear(myTimer); //nevermind

See also

Function.delay, Function.periodical

Abstract

Abstract class, to be used as singleton.  Will add .extend to any object

Arguments

an object

Returns

the object with an .extend property, equivalent to $extend.

window

Some properties are attached to the window object by the browser detection.

Note

browser detection is entirely object-based.  We dont sniff.

Properties

window.iewill be set to true if the current browser is internet explorer (any).
window.ie6will be set to true if the current browser is internet explorer 6.
window.ie7will be set to true if the current browser is internet explorer 7.
window.geckowill be set to true if the current browser is Mozilla/Gecko.
window.webkitwill be set to true if the current browser is Safari/Konqueror.
window.webkit419will be set to true if the current browser is Safari2 / webkit till version 419.
window.webkit420will be set to true if the current browser is Safari3 (Webkit SVN Build) / webkit over version 419.
window.operais set to true by opera itself.

Documentation by Aaron Newton & Mootools Developers, generated by NaturalDocs and GeSHi