Passing object as parameter to constructor function and copy its properties to the new object?

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);
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)