2

I am trying to make the method getColor() non-configurable, but when I tried to refer to the current instance property of the Fruit "class" using this.color it did't work. Seems like this doesn't refer to the Fruitinstance. How can I refer to the instance?

The function body defined for the property isn't a mutator, here its just an example

Object.defineProperty(Fruit.prototype, 'getColor', {
    writable: false,
    configurable: false,
    enumerable: false,
    value: function(){
        return this.color;  // this refers to Object here
    }
});
  • 1
    Are you setting the color on the instance of Fruit, or do you have `this.color` defined inside the Fruit constructor function ? In either way `this.color` should refer to the instance of Fruit. What exactly do you mean by *it didn't work* ? – DavidDomain Sep 23 '16 at 11:28
  • I want to refer to the color variable of the Fruit's instance – Suman Kumar Das Nov 28 '16 at 13:59

0 Answers0