I am looking for a JS solution / design pattern that allows to call the function C.Test.init() multiple times with binding the window load event in the init() function. Unfortunately I cannot get this to work. Can anyone help me with this?
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'
});
Here's the JS Fiddle link: http://jsfiddle.net/4Ss8L/