Reputation: 836
I have a JS definition like this in a .js file which is included in my .html file.
function chat() {
this.sendNew() = function() {
[ .. ]
}
}
Now I want to add another .js file which can extend this function with more methods, like this
function chat() {
this.anotherMethod = function() {
}
}
Is this possible? If yes, how? :)
Upvotes: 0
Views: 48
Reputation: 11342
You can add methods/attributes to the .prototype
object:
chat.prototype.anotherMethod = function () {
// ...
}
Just remember that .prototype
is a property of functions, and then should be accessed by chat
, and not by one of its instances.
You can read more about .prototype
here.
Upvotes: 4