Assume I make a custom Object:
function MyObject() {
// define some properties
}
Now I want define a private method in the prototype:
MyObject.prototype = {
// by doing this I defined a public method, how can I define a private method?
myMethod: function() {
//some code
}
}
Then I want to call the function in the constructor like this:
function MyObject() {
// define some properties
call myMethod()
}
How can I do it?
this.myMethod(). When creating a class and an instance of that class with thenewkeyword the object gets prototyped linked.thiswill refer to the current instance of that class. An awesome book series going pretty in depth and FREE is: github.com/getify/You-Dont-Know-JS You can read all about this stuff!