yui-ext支持把函数绑定到不同作用域,yutil.js中有代码如下:
Function.prototype.createCallback = function(){
var args = arguments;
var method = this;
return function() {
return method.apply(window, args);
};
};
调用方法:
function t(a){
alert(a);
}
var x = t.createCallback("abc");
window.x();
这样,t就成为window的方法了
Function.prototype.createCallback = function(){
var args = arguments;
var method = this;
return function() {
return method.apply(window, args);
};
};

function t(a){
alert(a);
}
var x = t.createCallback("abc");
window.x();
本文介绍 YUI-Ext 库中如何使用 Function.prototype.createCallback 方法将函数绑定到不同的作用域,通过示例展示了如何将一个普通函数变成全局对象 window 的方法。

1165

被折叠的 条评论
为什么被折叠?



