Defines a lazy constant on a class prototype
name of the property
function called when the property is accessed the first time
Optional
target
class Database { constructor(url) { this.url = url; }}definePrototypeLazyConstant(Database, 'connection', function() { return createDatabaseConnection(this.url);});const db = new Database('mongodb://localhost');// Connection is established only when first accessedconsole.log(db.connection); Copy
class Database { constructor(url) { this.url = url; }}definePrototypeLazyConstant(Database, 'connection', function() { return createDatabaseConnection(this.url);});const db = new Database('mongodb://localhost');// Connection is established only when first accessedconsole.log(db.connection);
Defines a lazy constant on a class prototype