I\'m wondering when I should use
Object.defineProperty
to create new properties for an object. I\'m aware that I\'m able to set things lik
Features like 'enumerable' are rarely used in my experience. The major use case is computed properties:
var myObj = {}; myObj.width = 20; myObj.height = 20; Object.defineProperty(myObj, 'area', { get: function() { return this.width*this.height; } }); console.log(myObj.area);