5

Helo there,

just a quick question, I'm using a pseudo-classical pattern to create objects in JS and I was wondering how do I actually create a private method that is accessible only inside the object.

let's say I want to add a private method XY() to object Animal. Does this kind of pattern allow me to create a private method?

function Animal(name) {
  this.name = name
}

Animal.prototype = {
  canWalk: true,
  sit: function() {
    this.canWalk = false
    alert(this.name + ' sits down.')
  }
}

Thanks in advance, Alex

Wracker
  • 589
  • 10
  • 32

0 Answers0