我有在一些开发工具中调试 JS 和 jQuery 脚本的习惯。我意识到 Chrome 开发工具将 x.fn.x.init 显示为 $() 和 $(this) 的值。但是我不知道这些价值是什么:
Code
<!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>
这实际上是实例化背后的真实代码$
看看github源码 https://github.com/jquery/jquery/blob/master/src/core.js#L76
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 https://github.com/jquery/jquery/blob/master/src/core.js#L263
// Give the init function the jQuery prototype for later instantiation
jQuery.fn.init.prototype = jQuery.fn;
由于您使用的是缩小版本,因此它会变成您所看到的样子。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)