Ext中Function类新增了一些比较实用的方法
createInterceptor( Function fcn, [Object scope] ) : Function
创建阻断方法,如果fcn返回false,原方法将不会被执行
createSequence( Function fcn, [Object scope] ) : Function
创建组合方法,执行原方法+fcn
defer( Number millis, [Object obj], [Array args], [Boolean/Number appendArgs] ):Number
定时执行,隔millis毫秒后执行原方法
一下是写的一些一个例子页面
exttry.html
<!
DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"
>
< html >
< head >
< meta http-equiv ="Content-Type" content ="text/html; charset=utf-8" />
< link rel ="stylesheet" type ="text/css" href ="../resources/css/ext-all.css" />
<!-- GC --><!-- LIBS -->
< script type ="text/javascript" src ="../adapter/ext/ext-base.js" > ...
</ script >
<!-- ENDLIBS -->
< script type ="text/javascript" src ="../ext-all-debug.js" > ...
</ script >
< script type ="text/javascript" src ="exttry.js" ></ script >
< title > ext try </ title >
</ head >
< body >
< div id ="logtxt" ></ div >
< div id ="showdefer" ></ div >
</ body >
</ html >
< html >
< head >
< meta http-equiv ="Content-Type" content ="text/html; charset=utf-8" />
< link rel ="stylesheet" type ="text/css" href ="../resources/css/ext-all.css" />
<!-- GC --><!-- LIBS -->
< script type ="text/javascript" src ="../adapter/ext/ext-base.js" > ...
</ script >
<!-- ENDLIBS -->
< script type ="text/javascript" src ="../ext-all-debug.js" > ...
</ script >
< script type ="text/javascript" src ="exttry.js" ></ script >
< title > ext try </ title >
</ head >
< body >
< div id ="logtxt" ></ div >
< div id ="showdefer" ></ div >
</ body >
</ html >
exttry.js
/**/
/**
* @author Administrator
*/
/**/ /**
* msg
*/
function log(msg) ... {
var logtxt = Ext.get("logtxt");
logtxt.update(logtxt.dom.innerHTML+'<br>'+msg);
}
function clearlog() ... {
var logtxt = Ext.get("logtxt");
logtxt.update('');
}
Ext.onReady( function () ... {
var commonfunc = function(strfunc)...{
log('此方法为示例通用方法'+strfunc);
}
//测试创建createInterceptor阻断方法,阻断方法返回值为false
var func1 = commonfunc.createInterceptor(function()...{
log('阻断方法,返回值为false');
return false;
});
func1('func1');
//测试创建createInterceptor阻断方法,阻断方法返回值为true
var func2 = commonfunc.createInterceptor(function()...{
log('阻断方法,返回值为true');
return true;
});
func2('func2');
//测试createSequence顺序执行方法
var func3 = commonfunc.createSequence(function()...{
log('顺序执行方法');
});
func3('func3');
//测试defer方法,推迟3秒执行
var deferfunc = function()...{
var showdefer = Ext.get('showdefer');
showdefer.update('deferfunc方法执行');
}
deferfunc.defer(3000);
}
);
* @author Administrator
*/
/**/ /**
* msg
*/
function log(msg) ... {
var logtxt = Ext.get("logtxt");
logtxt.update(logtxt.dom.innerHTML+'<br>'+msg);
}
function clearlog() ... {
var logtxt = Ext.get("logtxt");
logtxt.update('');
}
Ext.onReady( function () ... {
var commonfunc = function(strfunc)...{
log('此方法为示例通用方法'+strfunc);
}
//测试创建createInterceptor阻断方法,阻断方法返回值为false
var func1 = commonfunc.createInterceptor(function()...{
log('阻断方法,返回值为false');
return false;
});
func1('func1');
//测试创建createInterceptor阻断方法,阻断方法返回值为true
var func2 = commonfunc.createInterceptor(function()...{
log('阻断方法,返回值为true');
return true;
});
func2('func2');
//测试createSequence顺序执行方法
var func3 = commonfunc.createSequence(function()...{
log('顺序执行方法');
});
func3('func3');
//测试defer方法,推迟3秒执行
var deferfunc = function()...{
var showdefer = Ext.get('showdefer');
showdefer.update('deferfunc方法执行');
}
deferfunc.defer(3000);
}
);
执行结果:
阻断方法,返回值为false
阻断方法,返回值为true
此方法为示例通用方法func2
此方法为示例通用方法func3
顺序执行方法
deferfunc方法执行