arjit nair
arjit nair

Reputation: 51

Javascript extends does not work

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
var animal = {
    type: "mammal"
};

var dog = {
    sound: "bark"
};

dog.extends(animal);
alert(dog.type);
});
</script>

The above code is not alerting, and erroring out saying that undefined is not a function. Any idea why?

Upvotes: 0

Views: 410

Answers (1)

Dmitry
Dmitry

Reputation: 7246

try this

    $(document).ready(function(){
    var animal = {
        type: "mammal"
    };

    var dog = {
        sound: "bark"
    };

    $.extend(dog, animal);
    alert(dog.type);
    });

http://jsfiddle.net/auekn4f1/

Upvotes: 3

Related Questions