Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试将数组作为属性添加到其构造函数中的对象,如下所示:
let object { entries = [], }
但是,当我尝试访问“条目”属性时,无论是在对象本身的函数内部还是在外部函数中,它都不会被识别为数组。
我认为您在构造对象时只是有语法错误,访问对象中的数组应该没有任何问题:
let object = { entries: [], getEntries() { return this.entries; } } object.entries.push('it works'); console.log(object.entries) console.log(object.getEntries())