为什么 javascript 允许 $ 作为函数名? [英] why javascript permits $ for name of functions?
问题描述
我开始喜欢 jQuery,但作为 PHP 开发人员,我讨厌使用它
I am starting to love jQuery but as PHP developer I hate using that
$().stuff
众所周知,$
在 PHP 中标记变量.我猜 javascript 中的 jQuery 声明了一个这样的函数
as everyone know $
in PHP marks variables. I guess jQuery in javascript declares a function like this
function $(element) {/*stuff*/}
javascripts 是否允许 $
作为 func 的名称?这是一种好的行为吗?
Does javascripts permits $
as the name of a func? Is that a good behaviour?
我知道只有标准的 [0-9a-zA-Z_]
可以是 funcs/vars 的名称.
I knew only standard [0-9a-zA-Z_]
could be the name of funcs/vars.
我错过了什么吗?
谢谢
推荐答案
你可以做
var whatever = $.noConflict();
现在你可以使用 whatever(..)
而不是 $(...)
now you can use whatever(..)
instead of $(...)
文档位于 http://api.jquery.com/jQuery.noConflict/
并引用值、变量和文字
JavaScript 标识符必须以开头带有字母、下划线 (_) 或美元符号($);后续字符也可以是数字(0-9).
A JavaScript identifier must start with a letter, underscore (_), or dollar sign ($); subsequent characters can also be digits (0-9).
这篇关于为什么 javascript 允许 $ 作为函数名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!