I've been using jQuery.extend to replace default properties like this
var Car = function(options){
var defaultOptions = {
color: "hotpink",
seats: {
material: "fur",
color: "black",
count: 4
},
wheels: 4
}
this.options = $.extend(true,{},defaultOptions,options);
}
var myCar = new Car({
color: "blue",
seats: {
count: 2,
material: "leather"
}
});
alert(myCar.options.color); // "blue"
alert(myCar.options.seats.color); // "black"
alert(myCar.options.seats.count); // 2
While it works great, I'd like to know the best way to achieve similar results without any libraries. I just want to define some default settings in a function and replace them with settings from arguments, would be an overkill to include a library every time I do that.