Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.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 为什么在e.fn.e.init或x.fn.x.init(chrome调试器中的jQuery实例名称)中还有第二个e或x?_Javascript_Jquery - Fatal编程技术网

Javascript 为什么在e.fn.e.init或x.fn.x.init(chrome调试器中的jQuery实例名称)中还有第二个e或x?

Javascript 为什么在e.fn.e.init或x.fn.x.init(chrome调试器中的jQuery实例名称)中还有第二个e或x?,javascript,jquery,Javascript,Jquery,有时,在检查jQuery对象时,您会看到x.fn.x.init。或者,在这个页面上,它被缩小为e.fn.e.init,其中x==e==jQuery,尽管我不确定第二个e或x是什么 考虑以下事项:在本页的控制台中: $ >> function (a,b){return new e.fn.init(a,b,h)} [$()] >> [e.fn.e.init[0]] 0是类似jQuery对象的数组的长度。但是,e.fn.init如何到达e.fn.e.init?第二个e是什么

有时,在检查jQuery对象时,您会看到
x.fn.x.init
。或者,在这个页面上,它被缩小为
e.fn.e.init
,其中
x==e==jQuery
,尽管我不确定第二个
e
x
是什么

考虑以下事项:在本页的控制台中:

$
>> function (a,b){return new e.fn.init(a,b,h)}

[$()]
>> [e.fn.e.init[0]]
0是类似jQuery对象的数组的长度。但是,
e.fn.init
如何到达
e.fn.e.init
?第二个e是什么

更新

我刚刚在我的页面上包含了一个未缩小的版本,它显示为
jQuery.fn.jQuery.init
。我真的很困惑为什么
jQuery
会出现两次


我刚刚在控制台中尝试了
jQuery===jQuery.fn.jQuery
,结果返回false。实际上,
jQuery.fn.jQuery
是未定义的。奇怪…

我在谷歌的控制台api参考资料中没有找到任何关于这一点的明确解释,但我很想了解,以下是我的结论

这是jQuery中发生的事情的简化版本,只保留问题上下文中感兴趣的内容

var jQuery = function() {
    return new jQuery.fn.init();
};

jQuery.fn = jQuery.prototype = {
    init: function() {
        return this;
    }
};
var j = jQuery();
console.log(j);
>> jQuery.fn.jQuery.init {} 
在控制台中记录对象时,Chrome会显示某种内部标识符,这取决于对象在代码中的设置方式。它是在创建对象的命名空间中对象结构的某种表示形式。如果要反转fn和prototype(即
jQuery.prototype=jQuery.fn={…
),它将打印为
jQuery.fn.init
,而不是
jQuery.fn.jQuery.init

奇怪的是,如果要添加类似数组的属性(就像jQuery那样),它将在控制台中以不同的方式显示对象。我已尝试删除/添加属性,似乎添加了带有数字类型值的
length
属性和带有函数类型值的
splice
属性,您将在控制台中像数组一样显示对象(带方括号)


因此,我认为我们不应该太关注Chrome打印对象“名称”的方式或其格式…

也许这只是Chrome debugger的细微差别?可能有启发性:
var jQuery = function() {
    return new jQuery.fn.init();
};

jQuery.fn = jQuery.prototype = {
    init: function() {
        return this;
    },
    length: 0,
    splice: function(){}
};
jQuery.fn.init.prototype = jQuery.fn;

var j = jQuery();
console.log(j);
>> [init: function, splice: function]