我读javascript
Web应用程序和笔者使用下面的代码:是什么jQuery的(功能)做
mod.load = function(func){
$($.proxy(func, this));
};
有人可以帮助我了解为什么从jQuery.proxy
返回函数里面jQuery
包装。
这是一样的:
mod.load = function(func){
var temp = $.proxy(func, this);
temp();
};
我读javascript
Web应用程序和笔者使用下面的代码:是什么jQuery的(功能)做
mod.load = function(func){
$($.proxy(func, this));
};
有人可以帮助我了解为什么从jQuery.proxy
返回函数里面jQuery
包装。
这是一样的:
mod.load = function(func){
var temp = $.proxy(func, this);
temp();
};
它们并不相同,但它们具有相同的效果。你的第二个示例直接执行返回的函数,而jQuery(函数)将其绑定到像$(document).ready()
这样的onload。 mod.load大概是 onload,所以这没有什么区别。
是一样的,只是一个简写。
调用$()与函数参数相当于应用$(document).ready()到的功能:它等待DOM是调用前准备好。
因此,在第二个示例中,可能会在DOM准备好之前调用temp()
,具体取决于mod.load()
本身运行的时刻。
我认为使用$(),甚至是不好的做法,如果我已经在dom准备好之后加载模块。 – 2012-04-06 09:54:25
是的两者都是相似的。 '$ .proxy(func,this)'必须返回函数 – diEcho 2012-04-06 09:22:28