I have a JavaScript constructor like this:
function Box(obj) {
this.obj = obj;
}
which i want to pass an object as a parameter like this:
var box = new Box({prop1: "a", prop2: "b", prop3: "c"})
and gives me something like this:
box.obj.prop1
box.obj.prop2
box.obj.prop3
but I would like the properties to be directly on the object like this:
box.prop1
box.prop2
box.prop3
I know I could do something like this:
function Box(obj) {
this.prop1 = obj.prop1;
this.prop2 = obj.prop2;
this.prop3 = obj.prop3;
}
But that is not good because then my constructor would have to "know" before the names of the properties of the object parameter. What I would like is to be able to pass different objects as parameters and assign their properties directly as properties of the new custom object created by the constructor so I get box.propX and not box.obj.propX. Hope I am making myself clear, maybe I am measing something very obvious but I am a newbie so please need your help!
Thanks in advance.