✨closure as object
a closure used as an object (also called "module pattern").
Last updated
Was this helpful?
a closure used as an object (also called "module pattern").
Last updated
Was this helpful?
Was this helpful?
JS ⟩ value ⟩ function ⟩ closure ⟩ example ⟩ closure as object
a closure can be used as an object❗
(this pattern is also called module pattern)
replit:closure as object
// returns an object with closed over properties.
function Person(name, age) {
// 🔸 private properties
// • `name`, `age` are treated as private properties.
// ⭐️ the object to be returned (with exposed methods)
const obj = { sayHi };
// -------- define getter/setter/method --------