ded / klass

a utility for creating expressive classes in JavaScript
751 stars 78 forks source link

Suggest a .constants() method like .statics() which defines values you cannot change. #23

Open bcowgill opened 9 years ago

bcowgill commented 9 years ago

Consider this constructor:

'Thing': klass( function (name, fixed) { Object.defineProperty(this, 'CONST', { value: fixed, writable: false, enumerable: false, configurable: false }); this.gname = name; }).methods({ 'instMethod': function (param) { return this.CONST + ' ' + this.gname + ' ' + param; } }),

Would be cool if you could .constants({ 'CONST': fixed })

Either within the constructor ( to set the constant differently per instance ) or in the same place as the .methods() call to set constant values across all instances.

ded commented 9 years ago

this would be tough to implement since all values in JavaScript are not typed. :/