[color=red]拦截器示例:[/color]
[color=red]创建回调简单示例1:[/color]
[color=red]创建回调简单示例2 (与1的区别 另有博文说明):[/color]
[color=red]创建一个顺序执行的函数:[/color]
[color=red]创建一个延迟执行的函数:[/color]
var testFunc = function(a){
alert('executing...'+a);
}
var func = testFunc.createInterceptor(
function(){alert('intercepted');}
);
testFunc();//拦截器不会生效
func();//拦截器生效,所以必须使用createInterceptor返回的新函数去执行才能实现拦截,这与extjs的内部实现是吻合的
[color=red]创建回调简单示例1:[/color]
var testFunc = function(a){
alert('executing...'+a);
}
//创建一个回调函数
var callFunc = testFunc.createCallback('adsadfsf');
callFunc();//打出 executing...adsadfsf
[color=red]创建回调简单示例2 (与1的区别 另有博文说明):[/color]
var testFunc = function(a){
alert('executing...'+a);
}
//创建一个回调函数
var callFunc = testFunc.createDelegete(window,['adsadfsf']);
callFunc();//打出 executing...adsadfsf
[color=red]创建一个顺序执行的函数:[/color]
var testFunc = function(a){
alert('executing...'+a);
}
//创建一个回调函数
var callFunc = testFunc.createSequence(funciton(a){
alert('executing...2'+a);
});
callFunc();//打出 executing...adsadfsf 后接着打出 executing2...adsadfsf
[color=red]创建一个延迟执行的函数:[/color]
var testFunc = function(a){
alert('executing...'+a);
}
//window指作用域 ['haha']传入参数数组
testFunc.defer(2000,window,['haha'],true);//打出 executing...haha