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
Post a Comment