Skip to content Skip to sidebar Skip to footer

Jquery $.extend Without Overriding Target Properties

Is it possible to extend an object without overriding the properties that are already set? In the following example I'm looking for a way to add 2 wings to the cat, but keepings it

Solution 1:

Try something like -

for (prop in bird) {
    if(!cat.hasOwnProperty(prop)) {
        cat[prop] = bird[prop];
    }
}

After cat = {legs: 4, wings: 2}

Post a Comment for "Jquery $.extend Without Overriding Target Properties"