Reputation: 536
I have a class
class List<T>
which contains:
private _items = [];
public items() {
return this._items;
}
why does this work
private loop() {
for (var x of this._items) {
}
but this doesn't
private loop() {
for (var x of this.items) {
}
with the error given as: Type '() => any[]' is not an array type or a string type.
Upvotes: 0
Views: 80
Reputation: 11710
You're just missing the method invocation on this.items
- you want this.items()
instead, which will return the array, rather than using the method itself as the target of iteration.
Upvotes: 3