如果不是jQuery,Javascript中的美元符号是什么? [英] What is the dollar sign in Javascript, if not jQuery
问题描述
几年前我做了一些javascript / jQuery编程,我刚刚重新开始。当时美元符号用于所有jQuery功能,如果没有导入jQuery库,则未定义美元符号。
I did some javascript / jQuery programming a few years ago, and I just started up again. Back then the dollar sign was used for all the jQuery functionality, and if no jQuery library was imported, the dollar sign was not defined.
今天,我在一个没有javascript库的完全空的html文件中启动了Firefox,但是美元符号指向某个东西。如果我打开Firefox控制台并输入'$',我会得到function()
。
Today, I started up Firefox, in a completely empty html file with no javascript libraries, and yet the dollar sign points to something. If I open the Firefox console and type '$' I get "function()"
.
1)几年前没有分配美元符号是正确的,还是我记错了?
1) Is it correct that dollar sign was not assigned, a few years back, or do I remember wrong?
2)是什么美元符号,如果不是jQuery?
2) What is the dollar sign, if not jQuery?
推荐答案
1)美元是否正确标志没有分配,几年前,还是我记得错了?
1) Is it correct that dollar sign was not assigned, a few years back, or do I remember wrong?
这是正确的,仍然是真的。
That's correct and still true.
2)如果不是jQuery,美元符号是多少?
2) What is the dollar sign, if not jQuery?
Firefox 和 Chrome 实现 $
, $$
和其他几个作为帮助程序命令。两者都将 $$
设置为 document.querySelectorAll()
,并设置 $
到 document.querySelector
如果窗口。$
尚未定义。
Firefox and Chrome implement $
, $$
and several others as helper commands. Both will set $$
to document.querySelectorAll()
, and set $
to document.querySelector
if window.$
hasn't been defined.
所以你所看到的实际上并不是标准的JavaScript,而是浏览器开发者控制台中的助手。它也不是jQuery(只要你不在使用jQuery的页面上)。但是,它的行为接近 jQuery
的行为,关于 querySelector
(对于单个匹配)和 querySelectorAll
(对于多个匹配)提供与jQuery选择器几乎相同的强度。
So what you're seeing isn't actually standard JavaScript, but a helper in the developer console of your browser. It's also not jQuery (as long as you're not on a page using jQuery). However, it's behaviour is close to the one of jQuery
, concerning that querySelector
(for single matches) and querySelectorAll
(for multiple matches) give you almost the same strength as the jQuery selector.
这篇关于如果不是jQuery,Javascript中的美元符号是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!