Javascript中有什么方法,如何访问返回函数中的变量值?
function x (){
return{
foo:function(text){
value= text;
}
}
}
a=x();
a.foo("some text");
最佳答案
我个人的意见是使用面向对象的方法。
var SomeObject = function(){
var text = "";
this.setText = function(value){
text = value;
};
this.getText = function(){
return text;
};
};
var myObject = new SomeObject();
myObject.setText("This is the text");
alert(myObject.getText());
关于javascript - 返回函数中的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38623835/