说我有这个功能,我试图获得值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;
}
您可以通过将Value1和value2从实验函数中声明为1和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);
}