You could do this. There is probably also a jquery way…
function Box(obj) {
for (var fld in obj) {
this[fld] = obj[fld];
}
}
You can include a test for hasOwnProperty if you’ve (I think foolishly) extended object
function Box(obj) {
for (var fld in obj) {
if (obj.hasOwnProperty(fld)) {
this[fld] = obj[fld];
}
}
}
Edit
Ah, ha! it’s jQuery.extend
So, the jQuery way is:
function Box(obj) {
$.extend(this, obj);
}