The extend()
method of jQuery can be used to extend an object with another object, thus resulting in a new object that inherits all the properties and methods from the existing objects. For example:
var A = new function() { this.foo = 'Foo'; this.getFoo = function() { return this.foo; }; }; var B = new function() { this.url = location.href; this.getURL = function() { return this.url; }; }; var AB = $.extend(A, B);
We can check whether the resulting object has correctly inherited all the properties and methods by simply writing:
$('<p></p>').html(AB.getFoo()).insertAfter('#class-ab');
You can see this test here.