I recently discovered a method to create your own 'class' as shown below:
function Person(name, age){
this.name = name;
this.age = age;
}
Person.prototype.foo = function(){
// do something
}
Person.prototype.foo2 = function(){
// do something
}
var wong2 = new Person("wong2", "20");
Now, if both foo
and foo2
need to call another function called foo3
, where should I incorporate it?
I want foo3
to not be accessible by wong2
, so adding it directly in the Person
prototype is not an option.
Person.prototype.foo3 = function(){
// Another action
}
However, defining foo3
in the global scope doesn't seem like the most elegant solution. Any suggestions on how to handle this scenario?