jQuery global variable with getScript -
This object is decalred in foo.js, and has been modified in bar.js.
And when I getScript, I tried to get results.
foo.js P> bar.js Since you have declared a variable within a function, it is local for functions . What you can do is declare the variable out, but assign values inside jQuery's ready handler foo.js bar.js Demo:
/ * // It works fine, but I want to decalre it inside jQuery var myObject = {str: "hello world", num: "123"}; * / $ (Function () {// This makes my object global variable y myObject = {str: "Hello World", num: "123"}; Warning (myObject.str + "+ myObject.num); $ ; .getScript ("bar.js", function () {warning (myObject.str + "+ myObject.num);});});
$ (function () {myObject = {str: "new string", number: " 999 "};});
/ * // This works fine, but I want to decalre it within jQuery var myObject = {str: "hello world", num: "123"}; * / Var myObject; $ (Function () {//} This does not make my object global variable myoback {{str: "Hello World", num: "123"}; Alert (myObject.str + "+ myObject.num); $ .getScript ("Bar.js", function () {warning (myObject.str + "+ myObject.num);});});
$ (function () {myObject = {str: "new string", number: " 999 "};});
Comments
Post a Comment