Revealing Constructor
Revealing constructor is used in JavaScript, for example, to implement Promise
class. The constructor of Promise
class takes function with two parameters (resolve
and reject
) into constructor. It is perfect way to hide implementation details and there is no way somebody can mess around with resolve
and reject
after the instance if created.
Example - Read-only event emitter
The emit
function of ReadOnlyEmitter
can be called only in function that is passed into the constructor.
Last updated
Was this helpful?