jQuery's extend() method: simple test

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:


You can see this test here.

This entry was posted in by Gabriele Romanato. Bookmark the permalink.

Leave a Reply

Note: Only a member of this blog may post a comment.