Javascript add method to object

The Solution to Javascript add method to object is


you need to add it to Foo's prototype:

function Foo(){}
Foo.prototype.bar = function(){}
var x = new Foo()
x.bar()

~ Answered on 2012-11-23 00:46:41


Most Viewed Questions: