I've learned that you can create your own 'class' in this way:
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 foo
and foo2
both need to call another function named foo3
, where should I add it to?
I don't want foo3
to be called by wong2
, so I can't just use
Person.prototype.foo3 = function(){
// something else else
}
But if I define it in the global scope, I don't think it's very nice. Any suggestions?