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.
A property of an object can be explained as a variable that is attached to the object. Object properties are basically the same as ordinary JavaScript variables, except for the attachment to objects. The properties of an object define the characteristics of the object.
To add a new property to a Javascript object, define the object name followed by the dot, the name of a new property, an equals sign and the value for the new property.
A property descriptor is a simple JavaScript object associated with each property of the object that contains information about that property such as its value and other meta-data. In the above example, we have created a plain JavaScript object myObj using literal syntax with myPropOne and myPropTwo properties.
The Object.create() method creates a new object, using an existing object as the prototype of the newly created object.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With