jQuery的一个关键函数

jQuery.extend = jQuery.fn.extend = function() {
 // copy reference to target object
 var target = arguments[0] || {}, a = 1, al = arguments.length, deep = false;

 // Handle a deep copy situation

//这个IF条件基本上总是false,只有当target对象是布尔类型时才会是真,也就是这段代码好像没有什么作用

  if ( target.constructor == Boolean ) {   
  deep = target;
  target = arguments[1] || {};
 }

 // extend jQuery itself if only one argument is passed
 if ( al == 1 ) {
  target = this;
  a = 0;
 }

 var prop;

 for ( ; a < al; a++ )
  // Only deal with non-null/undefined values
  if ( (prop = arguments[a]) != null )
   // Extend the base object
   for ( var i in prop ) {
    // Prevent never-ending loop
    这一段代码不知道怎么搞的,说是用来阻止死循环,但我怎么也不明白他是如何阻止的,好像却了他也没什么影响。
    if ( target == prop[i] )
     continue;

    // Recurse if we're merging object values
    if ( deep && typeof prop[i] == 'object' && target[i] )
     jQuery.extend( target[i], prop[i] );

    // Don't bring in undefined values
    else if ( prop[i] != undefined )
     target[i] = prop[i];
   }

 // Return the modified object
 return target;
};

原文地址:https://www.cnblogs.com/ranzige/p/4059313.html