Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
124
rated 0 times [  127] [ 3]  / answers: 1 / hits: 22282  / 12 Years ago, mon, august 20, 2012, 12:00:00

Using this code I have this issue:


$.fn.dxwShow = function (options)
{
console.log(typeof(options));
dxwShowSetOptions(options);

setInterval(function(){
dxwShowChange();
}, dxwShowOptions.time);
};

var dxwShowOptions = {
"transition" : "SlideToggle",
"time": 1000
};

var dxwShowStatus = {
current : 0
};

function dxwShowSetOptions(options)
{
console.dir(typeof(options));

dxwShowOptions = Object.create(dxwShowOptions, options);
}

function dxwShowChange()
{
console.log(dxwShowOptions);
};

$(function()
{
options = {
"time": 700,
"debug" : true
};

$("#dxwShow").dxwShow(options);
});

I want to update dxwShowOptions and so I use Object.create passing first the object I wanna copy and so the object containing the new parameters. Where is the mistake?


PS :Chrome say that the object is at the Object.create line.


More From » javascript

 Answers
20

Object.create takes a map of property descriptors. options is not such a list.



See https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Object/create



If you wanted to still use Object.create, you'd need to modify options to be something more like



var options = {
time: {
enumerable: true,
configurable: true,
writable: true,
value: 700
},
debug: {
enumerable: true,
configurable: true,
writable: true,
value: true
}
};


But probably you want to use something more like _.extend.


[#83542] Friday, August 17, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
zachary

Total Points: 175
Total Questions: 89
Total Answers: 108

Location: Fiji
Member since Wed, Jul 14, 2021
3 Years ago
;