我在测试 JQuery 时看到了 Chrome 的自动完成建议,并看到了
$$
和 $x
的定义。它们是什么以及它们来自哪里?我看到了 Chrome 中变量 $x 的用途是什么?,但是 $$
是什么?
> $
function ( selector, context ) {
// The jQuery object is actually just the init constructor 'enhanced'
return new jQuery.fn.init( selector, context, rootjQuery );
} jquery.js?body=1:62
> $$
function $$() { [Command Line API] }
> $x
function $x() { [Command Line API] }
这是 ogooglebar。
我也有同样的问题。从 Ast Derek 发布的链接来看,默认情况下存在以下对象:
$() is an alias for document.querySelector()
$$() is an alias for document.querySelectorAll()
我检查了 Chrome 和 Firefox,这些似乎都适用。
当您链接 jQuery 时,$() 会被 jQuery 对象替换,但 $$() 仍然以其默认行为存在。对于刚接触这些东西的人来说非常困惑。