Javascript OOP - Private / Public Methods

Hi,

Just a quick question, I am using a pseudo-classical template to create objects in JS, and I was wondering how I can create a private method, accessible only inside the object.

let's say I want to add a private XY () method to an Animal object. Does this template allow you 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

+5
source share

Source: https://habr.com/ru/post/1204233/


All Articles