我在使用非常虚拟的JavaScript代码中的模块模式时出现问题。模块模式jQuery
此代码是可以正常使用:
;
var test = (function() {
var config = {
replacement: $('a')
};
var init = function() {
config.replacement.click(function(){
alert("hello");
});
}
return {
init: init
}
})();
$(document).ready(test.init());
任何人都可以告诉我为什么我不能使用:
;
var test = (function() {
var config = {
replacement: 'a'
};
var init = function() {
$(config.replacement).click(function(){
alert("hello world");
});
}
return {
init: init
}
})();
$(document).ready(test.init());
相反,当我点击我的网站的任何链接,这个代码不工作一个jQuery对象作为配置变量的“默认”初始化。
@ user1648170护理链接我吗? – alex
我刚刚回答了代码:) – user1648170