最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - What is x.fn.x.init[] value shown for $() and $(this) in chrome dev tools - Stack Overflow

matteradmin8PV0评论

I have a habbit of debugging JS and jQuery script in some developer tool. I realized Chrome Dev Tools showing x.fn.x.init as a value for $() and $(this). However I dont realize what are these value:

Code

<!DOCTYPE html>

<html lang="en" xmlns="">
<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>

I have a habbit of debugging JS and jQuery script in some developer tool. I realized Chrome Dev Tools showing x.fn.x.init as a value for $() and $(this). However I dont realize what are these value:

Code

<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3/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>

Share Improve this question edited Jul 25, 2013 at 14:19 Mahesha999 asked Jul 25, 2013 at 12:34 Mahesha999Mahesha999 25k30 gold badges130 silver badges210 bronze badges 2
  • when I type $() in chrome console on page with jquery I get empty array [] as a result. Are you including other libraries that are using the $ symbol? $(this) inside of document ready function should return the document object wrapped by jquery object. – CodeToad Commented Jul 25, 2013 at 12:43
  • added code, those script files are present in the same folder as this html page – Mahesha999 Commented Jul 25, 2013 at 14:19
Add a ment  | 

1 Answer 1

Reset to default 7

This is actually the REAL code behind instantiating $

Take a look at the 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;
    .....

and then at line 263

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

Since you are using the minified version, this gets turned into what you see.

Post a comment

comment list (0)

  1. No comments so far