接触jquery闭包的问题

huyang77 2014-04-07 06:39:21

;(function($)){
$.fn.extend({
ale:function(op){
op=$.extend({

},op);
}
});
}
op=$.extend({

},op);
//上面这段代码},op); 是啥意思 请楼下说的详细点谢谢 !比如:传递参数给谁,什么时候这样写

新手求大神带路
...全文
174 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
天际的海浪 2014-04-11
  • 打赏
  • 举报
回复
对op对象进行浅克隆,这样做应该是要让函数的形参对象与实参对象分别独立, 不让对形参对象的修改影响到实参对象
liuxingfffff 2014-04-11
  • 打赏
  • 举报
回复
hwhwzy 2014-04-11
  • 打赏
  • 举报
回复
huyang77 2014-04-09
  • 打赏
  • 举报
回复
求个通俗的解释
scscms太阳光 2014-04-08
  • 打赏
  • 举报
回复
function () {
    var options, name, src, copy, copyIsArray, clone, target = arguments[0] || {},
        i = 1,
        length = arguments.length,
        deep = false;

    // Handle a deep copy situation
    if (typeof target === "boolean") {
        deep = target;
        target = arguments[1] || {};
        // skip the boolean and the target
        i = 2;
    }

    // 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 (length === i) {
        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;
}
这是源码。
huyang77 2014-04-08
  • 打赏
  • 举报
回复
求解释
yang_1224 2014-04-07
  • 打赏
  • 举报
回复
看jQuery的源码 个人觉得op=$.extend({},op);是将{}以及op进行整合 源码显示是将op的属性添加到{}中再返回

87,920

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧