I'm trying to make a change in one spot to affect the config object passed into all instantiations of an object. The object is made available globally as follows:
function Crayons(){
return {
foo: ThirdPartyFoo
}
}
The object is initialized in my project with var myFoo = new Crayons().foo({color: "red"});
I'd like to make {color: "blue"}
the default, so that if someone doesn't pass in a color, blue is set.
I tried doing
function Crayons(){
var fooWithDefaults = function(){
this = new ThirdPartyFoo(arguments); //this is invalid
this.color = "blue"; //and this would overwrite color if it was set
}
return {
foo: fooWithDefaults
}
}
But the new
keyword is throwing me off, as I don't know how to create a javascript constructor that essentially says this = new 3rdPartyFoo
.
What am I missing?