0

I am trying to implement a range property on a sequence object with the following code:

function RangeSeq(from, to) {
  this.array = [];
  this.from = from;
  this.to = to;
  this.arraySeq = new ArraySeq(this.range);
}

Object.defineProperty(RangeSeq.prototype, "range", {
  get: function() {
    for (var i = this.from; i <= this.to; i++) {
      array.push[i];
      console.log(this.array)
    } 
    return array;
  }
});

However, after running the code above, the array object still remains empty. Why is this so and what's the right way to solve this?

2
  • this.array not just array
    – Pointy
    Commented Dec 2, 2016 at 14:57
  • @Pointy thanks a lot Commented Dec 2, 2016 at 15:07

1 Answer 1

5

You used square brackets and not referring to this.array. It should be

this.array.push(i);
2
  • also it has to be this.array
    – Pointy
    Commented Dec 2, 2016 at 14:57
  • @Pointy updated the answer to contain this also, thank you :) Commented Dec 2, 2016 at 14:58

Not the answer you're looking for? Browse other questions tagged or ask your own question.