I have the following method in my class MakeRequest.js:
export default class MakeRequest{
send() {
var data = 'foo';
var data2 = 'bar';
return [data, data2];
}
}
I am trying to access data and data2 from a different class:
(array) => MakeRequest.send(JSON.stringify(query));
alert(array[0]);
The error message displayed is
Can't find variable: array
Why is 'array' not accessible?
array
is out of scope. Your lambda ends with the send
call. If you're wanting to alert within it, and not return the output of that method call, do something like this:
(array) => {
MakeRequest.send(JSON.stringify(query));
alert(array[0]);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.