I just defined object and it's property inside a function:
function objectDefinition() {
const object = {
property: value
}
}
How can I get it from outside the function? Would something like the code below work?
object = {}
function objectDefinition() {
const object = {
property: value
}
}
If it doesn't work, is there any other way?
You should return the object from the function.
function objectDefinition() {
const object = {
property: value
}
return object;
}
let someVar = objectDefinition();
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.