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

admin2025-04-26  1

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.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745647409a311961.html

最新回复(0)