Suppose I have a Foo object
Foo
How can I extend this object by adding a bar() method and also ensure that future instances of Foo have this method?
bar()
you need to add it to Foo's prototype:
function Foo(){} Foo.prototype.bar = function(){} var x = new Foo() x.bar()
1.4m articles
1.4m replys
5 comments
56.9k users