javascript - JSHint not handling defineProperty syntax? -


i have piece of code in constructor function:

    object.defineproperty(this, "color", {         : function() {             return color;         },         set : function(newval) {             color = newval;             this.path.attr("stroke", color);         }      }); 

jshint warning 'color' not defined. supposed define 'color' somehow before configuring defineproperty?

(i have tried using 'this.color' inside defineproperty, causes infinite loops)

thanks

color indeed undefined. need store information elsewhere.

you via closure:

var color; object.defineproperty(this, "color", {     : function() {         return color;     },     set : function(newval) {         color = newval;         this.path.attr("stroke", color);     }  }); 

or another, non-enumerable (so doesn't show on for in) , non-configurable (to avoid overrides) property:

object.defineproperty(this, "_color", {   configurable: false,   writable: true,   enumerable: false });  object.defineproperty(this, "color", {     : function() {         return this._color;     },     set : function(newval) {         this._color = newval;         this.path.attr("stroke", color);     }  }); 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -