I'm trying to implement an object in which there can be an arbitrary number of properties and a function method that receives the input parameter string and checks if there is a property with that name. Properties and method cannot be overridden, deleted, and new functionality cannot be added to the object. I need this to resemble enuma.
var SomeObj = {}; Object.defineProperties(SomeObj, { prop1: { value: 1, writable: false, configurable: false, enumerable: true }, isAllowed: { value: function (type) { return this.hasOwnProperty(type); }, writable: false, configurable: false, enumerable: true } }); Object.preventExtensions(SomeObj); It’s embarrassing that in the articles I didn’t see such a syntax ( value: function () {} ), besides autocompletion of phpstorm on the SomeObj method shows as a property (without brackets at the end that need to be manually delivered) which is not surprising because it as a property and declared, but it is not obvious. In a word, is there another way to declare a method for an object that cannot be later redefined.
definePropertytwo approaches, via value, and via get / set: mdn - Grundy