的document.body在JavaScript是直接引用表示所述的DOM元素<body>的页面的一部分.
该$()部分取决于它的使用方式.$可以是变量名,并()在变量或属性名称后尝试调用存储在该变量或属性中的函数.
所以如果你有:
var $ = function() { alert('howdy'); };
Run Code Online (Sandbox Code Playgroud)
然后这个:
$();
Run Code Online (Sandbox Code Playgroud)
...将调用该函数,并触发警报.
函数可以接受参数,因此你可以修改上面的函数来接受document.body元素作为参数,以及alert()它innerHTML(例如);
// alerts the innerHTML of the element it receives
var $ = function( elem ) { alert( elem.innerHTML ); };
$( document.body ); // Passes the element when calling the $ function
Run Code Online (Sandbox Code Playgroud)