Ext中的createdelegate()方法
关于回调函数指定参数问题,由来已久,extjs简洁优雅完美的解决了这个问题,今天来学习一下(不推荐 createCallback )
?
?
createDelegate ( [Object obj ] , [Array args ] , [Boolean/Number appendArgs ]? ) : Function
那么 调用
function2时传的参数被忽略,args数组参数作为function1的参数运行。调用
function2时传的参数放在args数组前面合成一个新的数组,作为function1的参数运行。
Function.prototype.createDelegate?=?function(obj,?args,?appendArgs){??????????var?method?=?this;??????????return?function()?{??????????????var?callArgs?=?args?||?arguments;??????????????if(appendArgs?===?true){??????????????????callArgs?=?Array.prototype.slice.call(arguments,?0);??????????????????callArgs?=?callArgs.concat(args);??????????????}else?if(typeof?appendArgs?==?"number"){??????????????????callArgs?=?Array.prototype.slice.call(arguments,?0);???//?copy?arguments?first??????????????????var?applyArgs?=?[appendArgs,?0].concat(args);???//?create?method?call?params??????????????????Array.prototype.splice.apply(callArgs,?applyArgs);???//?splice?them?in??????????????}??????????????return?method.apply(obj?||?window,?callArgs);??????????};??????}?