Syntax:
var sheep = {sizes:100, eat:100, colors:'white',running:function(){ return this.sizes+this.eat; } };
is an object literal. It defines an instance of an object, but not the class that defines it. Thus, there is no way to βupdateβ another instance of the object.
Take a look at jQuery extend functionality:
var blacksheep = { } $.extend(blacksheep, sheep, { color: black });
This will copy all the properties of the sheep into blacksheep , and then combine the third parameter into blacksheep , effectively doing what you want.
source share