Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/394.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 了解是否签入扩展功能_Javascript - Fatal编程技术网

Javascript 了解是否签入扩展功能

Javascript 了解是否签入扩展功能,javascript,Javascript,我试图理解jquery扩展函数,基本上看一下下面的代码: function () { var src, copyIsArray, copy, name, options, clone, target = arguments[0] || {}, i = 1, length = arguments.length, deep = false; // Handle a deep copy situation if (typeof

我试图理解jquery扩展函数,基本上看一下下面的代码:

function () {
    var src, copyIsArray, copy, name, options, clone, target = arguments[0] || {},
        i = 1,
        length = arguments.length,
        deep = false;

    // Handle a deep copy situation
    if (typeof target === "boolean") {
        deep = target;

        // skip the boolean and the target
        target = arguments[i] || {};
        i++;
    }

    // Handle case when target is a string or something (possible in deep copy)
    if (typeof target !== "object" && !jQuery.isFunction(target)) {
        target = {};
    }

    // extend jQuery itself if only one argument is passed
    if (i === length) {
        target = this;
        i--;
    }

    for (; i < length; i++) {
        // Only deal with non-null/undefined values
        if ((options = arguments[i]) != null) {
            // Extend the base object
            for (name in options) {
                src = target[name];
                copy = options[name];

                // Prevent never-ending loop
                if (target === copy) {
                    continue;
                }

                // Recurse if we're merging plain objects or arrays
                if (deep && copy && (jQuery.isPlainObject(copy) || (copyIsArray = jQuery.isArray(copy)))) {
                    if (copyIsArray) {
                        copyIsArray = false;
                        clone = src && jQuery.isArray(src) ? src : [];

                    } else {
                        clone = src && jQuery.isPlainObject(src) ? src : {};
                    }

                    // Never move original objects, clone them
                    target[name] = jQuery.extend(deep, clone, copy);

                    // Don't bring in undefined values
                } else if (copy !== undefined) {
                    target[name] = copy;
                }
            }
        }
    }

    // Return the modified object
    return target;
}
这条线到底在检查什么

如果在此检查之前仔细查看几行代码,您将看到以下内容:

if ((options = arguments[i]) != null) {
            // Extend the base object
            for (name in options) {
                src = target[name];
                copy = options[name];

                // Prevent never-ending loop
                if (target === copy) {
                    continue;
                }
为选项分配一个值并检查其是否为
null
,然后,
for..in
循环迭代选项的键,然后您会看到
target[name]
Options[name]
的值被分配给临时变量

我基本上了解背景,但我仍然不理解下面的代码:

                // Prevent never-ending loop
                if (target === copy) {
                    continue;
                }
有人能解释一下上面这条线在干什么吗?我也不理解上面的评论

// Prevent never-ending loop. 
p.S.::为了简单起见,我们假设:

target = {};

它避免了用对象本身深度扩展对象时的循环。换句话说,它处理案例
var foo={};$。扩展(true,foo,{bar:foo})
@FrédéricHamidi,很有趣,但我仍然不知道if在检查什么。好吧,你说除了
if
语句之外,你理解大部分代码。如果我之前的评论没有帮助,你可能会对大多数情况持乐观态度。你真的在问
target
copy
实际上是什么?还是我遗漏了什么?
target = {};