我正在寻找一种JS解决方案/设计模式,它允许通过在init()函数中绑定窗口加载事件来多次调用函数C.Test.init()。不幸的是,我不能让它工作。有人能帮我吗?
var C = {};
C.Test = (function(C)
{
var me = {};
me.init = function(config)
{
me._config = config;
$(window).bind('load.' + config.name, me, me.sayHello);
}
me.sayHello = function(e)
{
// this doesn't work:
document.write('HELLO ' + me._config.name + '<br>');
// this doesn't work either:
document.write('SALVE ' + e.data._config.name + '<br>');
}
return {
init : me.init
}
})(C);
C.Test.init({
name: 'John'
});
C.Test.init({
name: 'Kate'
});这是JS Fiddle链接:http://jsfiddle.net/4Ss8L/
发布于 2012-03-16 17:34:52
在我看来,这是一个封闭的问题
http://jsfiddle.net/4Ss8L/2/
看看这个。
https://stackoverflow.com/questions/9734402
复制相似问题