JS copies all the properties of object s to object r of native JS +jquery

  • 2020-03-30 01:28:52
  • OfStack

Native writing:



  mix: function (r, s, is_overwrite) { //TODO:
   if (!s || !r) return r;
   for (var p in s) {
    if (is_overwrite !== false || !(p in r)) {
     r[p] = s[p];
    }
   }
   return r;
  }

JQuery is so easy to write


var a={
        aa:1,
        ab:2
    };
var b={
        ba:1,
        bb:2
    };
    $.extend(a,b);
    console.info(a);


Related articles: