让我说我有这个功能,我试图获得值1和2的值,这是正确的方法。 1.当退出函数时,如何定义值1和值2 2.如何在不调用“doSomething”函数的情况下获取另一个函数的值
test.prototype.doSomething = function (){
test = new Execution(experiment);
function experiment(bla) {
forEach(function(bla) {
var value1 = bla.value1;
var value2 = bla.balue2;
console.log(value1); //defined
});
console.log(value1); //undefined
}
console.log(value1); //undefined
}
test.prototype.testSomething = function() {
var testSomething = values1;
}
答案 0 :(得分:0)
您可以尝试从实验函数中声明value1和value2,并为函数中的那些变量赋值。以下是代码:
test.prototype.doSomething = function (){
var value1, value2;
test = new Execution(experiment);
function experiment(bla) {
forEach(function(bla)
value1 = bla.value1;
value2 = bla.balue2;
console.log(value1);
});
console.log(value1);
}
console.log(value1);
}