Here is the code-
function setOptions(obj, options) {
if (!obj.hasOwnProperty('options')) {
obj.options = obj.options ? create(obj.options) : {};
}
for (var i in options) {
obj.options[i] = options[i];
}
return obj.options;
}
var x={};
setOptions(x, {prop1:2});
console.log(x);
setOptions(x,{prop1:3});
console.log(x);
I expected that the first setOptions()
call should assign a prop1:2
property to x
. And second setOptions()
call will reassign prop1
as 3
. According to my assumption, the output should be-
first console.log output - {prop1:2}
second console.log output - {prop2:3}
But it is printing the following stuff in web console-
first console.log output - {prop1:3}
second console.log output - {prop2:3}
What am I missing in my assumption?