here is the code
test ('e');
function test(e) {
test2(e); //undefined
}
(function ($) {
function test2(e) {
alert('test');
}
})
Because of something restriction, i have to call like this. Anyone knows?
You can, by declaring test2 outside the anonymous function:
var test2; //Declare test2 in global
(function ($) {
test2 = function (e) { //define test2
alert('test'); //because test2 was declared in global,
}; // it will stay global.
})(jQuery);
test('e'); //Call test
function test(e) {
test2(e); //Since test2 can be access anywhere in your code,
} //it is now defined.
bind event on document and trigger it:
function test(e) {
var param=1;
param2=4;
jQuery(document).trigger('mytest2',[param,param2]);
}
(function ($) {
$(document).bind('mytest2',test2);
function test2(event,param,param2) {
alert('test '+param+' '+param2);
}
})(jQuery)
setTimeout(test,2000);