我有一个方法:
function calculateThings(newdata){
}
如何从其中返回全局变量?
谢谢!
抱歉没有详细说明。
var thisData = "";
function calculateThings(newData) {
thisData = newData.things.otherthings //has a value of 10;
}
alert(thisData) //returns nothing
我究竟做错了什么?
我有一个方法:
function calculateThings(newdata){
}
如何从其中返回全局变量?
谢谢!
抱歉没有详细说明。
var thisData = "";
function calculateThings(newData) {
thisData = newData.things.otherthings //has a value of 10;
}
alert(thisData) //returns nothing
我究竟做错了什么?
There doesn't seem to be much point in returning a global variable, the function can just set it and other functions reference it.
var setGlobal = (function(global) {
return function(value) {
global.someVarName = value;
}
}(this));
var readGlobal = (function(global) {
return function() {
return global.someVarName;
}
}(this));
setGlobal('foo');
alert(readGlobal()); // foo
alert(someVarName); // foo