Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/447.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.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 (a) { function d(g) { return typeof g == "object" ? g : { top: g, left: g } } var b = a.scrollTo = function (g, e, f) { a(window).scrollTo(g, e, f) };

(一些代码)(jQuery)

这是什么意思

(function (a) {
    function d(g) {
        return typeof g == "object" ? g : {
            top: g,
            left: g
        }
    }
    var b = a.scrollTo = function (g, e, f) {
        a(window).scrollTo(g, e, f)
    };
    b.defaults = {
        axis: "xy",
        duration: parseFloat(a.fn.jquery) >= 1.3 ? 0 : 1
    };
    b.window = function () {
        return a(window)._scrollable()
    };
    a.fn._scrollable = function () {
        return this.map(function () {
            if (!(!this.nodeName || a.inArray(this.nodeName.toLowerCase(), ["iframe", "#document", "html", "body"]) != -1)) return this;
            var g = (this.contentWindow || this).document || this.ownerDocument || this;
            return a.browser.safari || g.compatMode == "BackCompat" ? g.body : g.documentElement
        })
    };
    a.fn.scrollTo = function (g, e, f) {
        if (typeof e == "object") {
            f = e;
            e = 0
        }
        if (typeof f == "function") f = {
            onAfter: f
        };
        if (g == "max") g = 9E9;
        f = a.extend({}, b.defaults, f);
        e = e || f.speed || f.duration;
        f.queue = f.queue && f.axis.length > 1;
        if (f.queue) e /= 2;
        f.offset = d(f.offset);
        f.over = d(f.over);
        return this._scrollable().each(function () {
            function k(w) {
                j.animate(r, e, f.easing, w &&
                function () {
                    w.call(this, g, f)
                })
            }
            var h = this,
                j = a(h),
                i = g,
                m, r = {},
                u = j.is("html,body");
            switch (typeof i) {
            case "number":
            case "string":
                if (/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(i)) {
                    i =
                    d(i);
                    break
                }
                i = a(i, this);
            case "object":
                if (i.is || i.style) m = (i = a(i)).offset()
            }
            a.each(f.axis.split(""), function (w, v) {
                var q = v == "x" ? "Left" : "Top",
                    s = q.toLowerCase(),
                    y = "scroll" + q,
                    D = h[y],
                    H = b.max(h, v);
                if (m) {
                    r[y] = m[s] + (u ? 0 : D - j.offset()[s]);
                    if (f.margin) {
                        r[y] -= parseInt(i.css("margin" + q)) || 0;
                        r[y] -= parseInt(i.css("border" + q + "Width")) || 0
                    }
                    r[y] += f.offset[s] || 0;
                    if (f.over[s]) r[y] += i[v == "x" ? "width" : "height"]() * f.over[s]
                } else {
                    q = i[s];
                    r[y] = q.slice && q.slice(-1) == "%" ? parseFloat(q) / 100 * H : q
                }
                if (/^\d+$/.test(r[y])) r[y] = r[y] <= 0 ? 0 : Math.min(r[y], H);
                if (!w && f.queue) {
                    D != r[y] && k(f.onAfterFirst);
                    delete r[y]
                }
            });
            k(f.onAfter)
        }).end()
    };
    b.max = function (g, e) {
        var f = e == "x" ? "Width" : "Height",
            k = "scroll" + f;
        if (!a(g).is("html,body")) return g[k] - a(g)[f.toLowerCase()]();
        f = "client" + f;
        var h = g.ownerDocument.documentElement,
            j = g.ownerDocument.body;
        return Math.max(h[k], j[k]) - Math.min(h[f], j[f])
    }
})(jQuery);
(功能(a){
职能d(g){
返回类型g==“对象”?g:{
上图:g,
左:g
}
}
变量b=a.scrollTo=function(g,e,f){
a(窗口)。滚动到(g、e、f)
};
b、 默认值={
轴:“xy”,
持续时间:parseFloat(a.fn.jquery)>=1.3?0:1
};
b、 窗口=函数(){
返回一个(窗口)。\u可滚动()
};
a、 fn._scrollable=函数(){
返回此.map(函数(){
如果(!(!this.nodeName | | a.inArray(this.nodeName.toLowerCase(),[“iframe”,“#document”,“html”,“body”])!=-1)返回此信息;
var g=(this.contentWindow | | this).document | | this.ownerDocument | | this;
返回a.browser.safari | | g.compatMode==“BackCompat”?g.body:g.documentElement
})
};
a、 fn.scrollTo=函数(g,e,f){
if(类型e==“对象”){
f=e;
e=0
}
如果(f的类型==“函数”)f={
onAfter:f
};
如果(g=“max”)g=9E9;
f=a.extend({},b.defaults,f);
e=e | | f.速度| | f.持续时间;
f、 queue=f.queue&&f.axis.length>1;
如果(f.queue)e/=2;
f、 偏移量=d(f.偏移量);
f、 over=d(f.over);
返回此值。_scrollable()。每个函数(){
函数k(w){
j、 动画(r、e、f、w)&&
函数(){
w、 呼叫(这个,g,f)
})
}
var h=这个,
j=a(h),
i=g,
m、 r={},
u=j.is(“html,正文”);
开关(i型){
案例“编号”:
大小写“字符串”:
如果(/^([+-]=)?\d+(\.\d+)(px |%)?$/.test(i)){
我=
d(i);
打破
}
i=a(i,这个);
案例“对象”:
如果(i.is | | i.style)m=(i=a(i)).offset()
}
a、 每个(f轴拆分(“”),功能(w,v){
变量q=v==“x”?“左”:“顶部”,
s=q.toLowerCase(),
y=“滚动”+q,
D=h[y],
H=b.max(H,v);
如果(m){
r[y]=m[s]+(u?0:D-j.offset()[s]);
如果(f.保证金){
r[y]=parseInt(i.css(“margin”+q))| | 0;
r[y]-=parseInt(i.css(“边框”+q+“宽度”))| | 0
}
r[y]+=f.offset[s]| | 0;
如果(f.over[s])r[y]+=i[v==“x”?“宽度”:“高度”]()*f.over[s]
}否则{
q=i[s];
r[y]=q.slice&&q.slice(-1)=“%”?parseFloat(q)/100*H:q
}
如果(/^\d+$/.test(r[y])r[y]=r[y]它是一个闭包

它是代码的一部分,可以拥有自己的变量,这些变量不会与代码的其余部分共享

最后一个括号将参数传递给这个闭包

像这样:

(function (what, howmany){
    for (var i = howmany; i--;){
        alert(what);
    }
})("John",3);
在您的示例中,使用jquery对象作为参数调用闭包

有了它,您可以隔离代码这一部分的执行。它功能强大,必须熟悉如何编写真正的javascript


要查看有关javascript中闭包的更多信息,请参见:

这段代码是在什么上下文中编写的?您在哪里找到的?拜托!您真的希望有人逐行向您解释吗?请问一个更具体的问题。我的意思是(…)(jQuery)的用途是什么?将jQuery作为参数传递给此函数?扩展jQuery?