Contains Function prototypes, utility functions and Chain.
Valerio Proietti, http://mad4milk.net
MIT-style license.
Function.js | Contains Function prototypes, utility functions and Chain. |
Function | A collection of The Function Object prototype methods. |
Properties | |
pass | Shortcut to create closures with arguments and bind. |
bind | method to easily create closures with “this” altered. |
bindAsEventListener | cross browser method to pass event firer |
delay | Delays the execution of a function by a specified duration. |
periodical | Executes a function in the specified intervals of time |
Utility Functions | |
Functions | |
$clear | clears a timeout or an Interval. |
$type | Returns the type of object that matches the element passed in. |
Chain | |
Properties | |
chain | adds a function to the Chain instance stack. |
callChain | Executes the first function of the Chain instance stack, then removes it. |
clearChain | Clears the stack of a Chain instance. |
A collection of The Function Object prototype methods.
Properties | |
pass | Shortcut to create closures with arguments and bind. |
bind | method to easily create closures with “this” altered. |
bindAsEventListener | cross browser method to pass event firer |
delay | Delays the execution of a function by a specified duration. |
periodical | Executes a function in the specified intervals of time |
Shortcut to create closures with arguments and bind.
a function.
args | the arguments to pass to that function (array or single variable) |
bind | optional, the object that the “this” of the function will refer to. |
myFunction.pass([arg1, arg2], myElement);
method to easily create closures with “this” altered.
bind | optional, the object that the “this” of the function will refer to. |
a function.
function myFunction(){
this.setStyle('color', 'red');
// note that 'this' here refers to myFunction, not an element
// we'll need to bind this function to the element we want to alter
};
var myBoundFunction = myFunction.bind(myElement);
myBoundFunction(); // this will make the element myElement red.
cross browser method to pass event firer
bind | optional, the object that the “this” of the function will refer to. |
a function with the parameter bind as its “this” and as a pre-passed argument event or window.event, depending on the browser.
function myFunction(event){
alert(event.clientx) //returns the coordinates of the mouse..
};
myElement.onclick = myFunction.bindAsEventListener(myElement);
Delays the execution of a function by a specified duration.
ms | the duration to wait in milliseconds |
bind | optional, the object that the “this” of the function will refer to. |
myFunction.delay(50, myElement) //wait 50 milliseconds, then call myFunction and bind myElement to it
(function(){alert('one second later...')}).delay(1000); //wait a second and alert
Executes a function in the specified intervals of time
ms | the duration of the intervals between executions. |
bind | optional, the object that the “this” of the function will refer to. |
function $clear( timer )
clears a timeout or an Interval.
null
timer | the setInterval or setTimeout to clear. |
var myTimer = myFunction.delay(5000); //wait 5 seconds and execute my function.
myTimer = $clear(myTimer); //nevermind
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"
’function’ | if obj is a function |
’textnode’ | if obj is a node but not an element |
’element’ | if obj is a DOM element |
’array’ | if obj is an array |
’object’ | if obj is an object |
’string’ | if obj is a string |
’number’ | if obj is a number |
false | (boolean) if the object is not defined or none of the above, or if it’s an empty string. |
Properties | |
chain | adds a function to the Chain instance stack. |
callChain | Executes the first function of the Chain instance stack, then removes it. |
clearChain | Clears the stack of a Chain instance. |
adds a function to the Chain instance stack.
fn | the function to append. |
the instance of the Chain class.
var myChain = new Chain();
myChain.chain(myFunction).chain(myFunction2);
clears a timeout or an Interval.
function $clear( timer )
Returns the type of object that matches the element passed in.
function $type( obj )