【问题标题】:What is x.fn.x.init[] value shown for $() and $(this) in chrome dev toolschrome 开发工具中 $() 和 $(this) 显示的 x.fn.x.init[] 值是什么
【发布时间】:2013-07-25 12:34:09
【问题描述】:

我有在一些开发工具中调试 JS 和 jQuery 脚本的习惯。我意识到 Chrome 开发工具将 x.fn.x.init 显示为 $()​​ 和 $(this) 的值。但是我不知道这些价值是什么:

代码

<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<script src="jquery-2.0.2.min.js" ></script>
<script src="jquery.ui.widget.js" ></script>
<title></title>
<script type="text/javascript">

    $(document).ready(function () {
        var outstring = "";
        outstring = "" + $() + $(this);
    });

</script>
</head>
<body>
</body>
</html>

【问题讨论】:

  • 当我在带有 jquery 的页面上的 chrome 控制台中键入 $() 时,我得到空数组 [] 结果。您是否包括其他使用 $ 符号的库?文档就绪函数内部的 $(this) 应该返回由 jquery 对象包装的文档对象。
  • 添加的代码,这些脚本文件与这个html页面在同一个文件夹中

标签: javascript jquery developer-tools


【解决方案1】:

这实际上是实例化$背后的真实代码

看看github source

jQuery.fn = jQuery.prototype = {
    // The current version of jQuery being used
    jquery: core_version,

    constructor: jQuery,
    init: function( selector, context, rootjQuery ) {
        var match, elem;
    .....

然后在line 263

// Give the init function the jQuery prototype for later instantiation
jQuery.fn.init.prototype = jQuery.fn;

由于您使用的是缩小版,因此会变成您所看到的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-15
    • 2021-08-22
    • 2019-08-25
    • 2021-07-05
    • 1970-01-01
    • 2020-06-15
    • 1970-01-01
    • 2019-08-07
    相关资源
    最近更新 更多