Defines visible, non-configurable properties on an object.
Creates properties that are enumerable (show up in for...in loops and Object.keys) but cannot be modified or deleted. Useful for creating public APIs.
object to add properties to
properties to define
whether properties can be deleted or reconfigured
const api = {};definePublicProps(api, { version: '1.0.0', name: 'MyAPI'});console.log(api.version); // '1.0.0'console.log(Object.keys(api)); // ['version', 'name']api.version = '2.0.0'; // Fails silently or throws in strict mode Copy
const api = {};definePublicProps(api, { version: '1.0.0', name: 'MyAPI'});console.log(api.version); // '1.0.0'console.log(Object.keys(api)); // ['version', 'name']api.version = '2.0.0'; // Fails silently or throws in strict mode
class DataProcessor { constructor(config) { definePublicProps(this, { id: crypto.randomUUID(), createdAt: new Date() }); }} Copy
class DataProcessor { constructor(config) { definePublicProps(this, { id: crypto.randomUUID(), createdAt: new Date() }); }}
Defines visible, non-configurable properties on an object.
Creates properties that are enumerable (show up in for...in loops and Object.keys) but cannot be modified or deleted. Useful for creating public APIs.