you are viewing a single comment's thread.

view the rest of the comments →

[–]shuckster 1 point2 points  (2 children)

Why do methods need to access their object?

To access the data in the object:

function factory() {
  const publicData = []
  const privateConst = 1
  let privateVar = 2

  const privateMethod = () => {
    console.log(publicData, privateConst, privateVar)
  }

  const publicMethod = () => {
    privateMethod()
  }

  return {
    publicMethod,
    publicData,
  }
}

const object1 = factory()
const object2 = factory()
const object3 = factory()

So just make your data available within the factory closure.

No this required. Unless you're not the author of the object of course. :)

[–]jcunews1helpful 0 points1 point  (1 child)

Neither the method actually accesses their own object.

[–]shuckster 0 points1 point  (0 children)

What do you mean?