I try to write a javascript Self-Executing Anonymous Function
window.App = window.App || {}
(function (global) {
global.test = function () {
console.log('test');
}
})(App);
$(function () {
App.test();
})
but the fire bug tell me: ({}) is not a function
then I try move the (app)
in, like:
(function (global) {
global.test = function () {
console.log('test');
}
}(App));
then the firebug tell me :
App is not defined
So wht's wrong with my code?How can I do it in right way?
here is the demo