
Core contains common functions used in MooTools.
Returns the type of an object.
typeOf(obj);
var myString = 'hello'; typeOf(myString); // returns "string"
This method is equivalent to $type from MooTools 1.2, with the exception that undefined and null values now return 'null' as a string, instead of false.
Checks if an object is an instance of a particular type.
instanceOf(item, object)
var foo = []; instanceOf(foo, Array) // returns true instanceOf(foo, String) // returns false var myClass = new Class(); var bar = new myClass(); instanceOf(bar, myClass) // returns true
MooTools extends native types, like string, array or number to make them even more useful.
The types MooTools uses are:
Custom MooTools types are:
This method implements a new method to the type's prototype.
myType.implement(name, method);
or
myType.implement(methods);
or
Array.implement('limitTop', function(top){ for (var i = 0, l = this.length; i < l; i++){ if (this[i] > top) this[i] = top; } return this; }); [1, 2, 3, 4, 5, 6].limitTop(4); // returns [1, 2, 3, 4, 4, 4]
It is also possible to pass an object of methods:
String.implement({ repeat: function(times){ var string = ''; while (times--) string += this; return string; }, ftw: function(){ return this + ' FTW!'; } }); 'moo! '.repeat(3); // returns "moo! moo! moo! " 'MooTools'.ftw(); // returns "MooTools FTW!" ('MooTools'.ftw() + ' ').repeat(2); // returns "MooTools FTW! MooTools FTW! "
Adds one or more functions to the type. These are static functions that accept for example other types to parse them into the type, or other utility functions that belong to the certain type.
myType.extend(name, method);
or
myType.extend(methods);
or
RegExp.extend('from', function(regexp, flags){ return new RegExp(regexp, flags); }); Number.extend('parseCurrency', function(currency){ // takes a string and transforms it into a number to // do certain calculations });
Most methods of types can be used as generic functions. These are the already existing JavaScript methods, methods MooTools adds, or methods you implemented yourself.
var everyArgBiggerThanTwo = function(){ // Instead of this return Array.prototype.every.call(arguments, someFunction); // you can use return Array.every(arguments, someFunction); };
This is useful if methods of a certain type should be used as function of another type.
As the example above, it is used for the Arguments type, which is not a real array, so arguments.every(fn)
would not work. However, Array.every(arguments, fn)
does work in MooTools.
Type.methodName(thisArg[, arg1, arg2, ...]);
thisArg.method([arg1, arg2, ...]);
.This method has been deprecated and will have no equivalent in MooTools 1.3.
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 clearInterval or clearTimeout instead.
This method has been deprecated.
If you really need this function you can implement it like so:
var $defined = function(obj){ return (obj != undefined); }; // or just use it like this: if(obj != undefined){ // do something }
This method has been deprecated and will have no equivalent in MooTools 1.3.
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 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.
However $splat
does not transform Array-like objects such as NodeList or FileList in arrays, Array.from
does.
This method has been deprecated. Please use Date.now() instead.
var time = Date.now();
This method has been deprecated. Please use Function.attempt instead.
This method has been deprecated. Please use typeOf instead.
© Linux.ria.ua, 2008-2023 |