angularjs - extend recursive

前端 未结 6 1537
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-10 10:59

I would like to extend some properties recursive (aka. deep copy). much like jQuery does. I\'m not including jquery only b/c of one thing.

jQuery.extend( tru         


        
6条回答
  •  南方客
    南方客 (楼主)
    2020-12-10 11:43

    function deepExtend(destination, source) {
      for (var property in source) {
        if (source[property] && source[property].constructor &&
         source[property].constructor === Object) {
          destination[property] = destination[property] || {};
          arguments.callee(destination[property], source[property]);
        } else {
          destination[property] = source[property];
        }
      }
      return destination;
    }
    

    Plunker

    Src: https://gist.github.com/gregdangelo/2343158

提交回复
热议问题