Function: Function.from 返回方法;
Function: Function.attempt 尝试方法
Function.attempt(fn[, fn, fn, fn, ...]);
Function method: extend 继承;
var myFunction = function(){};
myFunction.extend('alert', function(text){
alert(text);
});
myFunction.alert('Hello!'); // alerts Hello!
// Using objects
myFunction.extend({
alert: function(text){
alert(text);
}
});
Function method: implement 为原型添加方法。
var myFunction = function(){};
myFunction.implement('alert', function(text){
alert(text);
});
var myInstance = new myFunction();
myInstance.alert('Hello!'); // alerts Hello!
// Using objects
myInstance.implement({
alert: function(text){
alert(text);
}
});
Function method: bind 绑定事件
function myFunction(){
// Note that 'this' here refers to window, not an element.
// the function must be bound to the element we want to manipulate.
this.setStyle('color', 'red');
};
var myBoundFunction = myFunction.bind(myElement);
myBoundFunction(); // makes myElement's text red
// To show how bind works the following example:
var myBoundFunction = myFunction.bind(anyVar);
// is roughly equivalent with
var myBoundFunction = function(){
return myFunction.call(this);
};
Function method: delay 延时方法发生 var timeoutID = myFunction.delay(delay[, bind[, args]]);
var myFunction = function(){ alert('moo! Element id is: ' + this.id); };
//wait 50 milliseconds, then call myFunction and bind myElement to it
myFunction.delay(50, myElement); // alerts: 'moo! Element id is: ... '
//an anonymous function which waits a second and then alerts
(function(){ alert('one second later...'); }).delay(1000);
//to stop the delay, clearTimeout can be used like so:
var timer = myFunction.delay(50);
clearTimeout(timer);
Function method: periodical 周期性执行方法
ar Site = { counter: 0 };
var addCount = function(){ this.counter++; };
addCount.periodical(1000, Site); //adds the number of seconds at the Site.
// the interval can be stopped using the clearInterval function
var timer = myFunction.periodical(1000);
clearInterval(timer);