JavaScript标识符中除了$之外还有哪些不寻常的字符?

时间:2021-09-18 00:45:25

I want a variable like $ that is sort of special, but I'm already using jQuery, so $ is taken.

我想要一个像$这样的变量,有点特别,但我已经在使用jQuery,所以$被采用了。

5 个解决方案

#1


If you want a special variable like $ but $ is already taken by jQuery, why not use something that starts with $, like $a or similar? Just make sure it's one that jQuery doesn't also define.

如果你想要一个特殊的变量,比如$,但是jQuery已经采用了$,为什么不使用以$开头的东西,比如$ a或者类似的?只要确保它是jQuery也没有定义的那个。

#2


Unfortunately, older javascript supports letters, numbers, underscores, and $ in identifiers. In javascript 1.5 and later you can use Unicode characters, but that would be a very bad idea as they can be a pain to enter into most editors, and certainly aren't something you would want to have to type very often.

不幸的是,较旧的JavaScript支持字母,数字,下划线和$ in标识符。在javascript 1.5和更高版本中你可以使用Unicode字符,但这是一个非常糟糕的主意,因为它们可能很难进入大多数编辑器,当然也不是你想要经常打字的东西。

Source

#3


The one I like it best:

我最喜欢的那个:

λ = Function;

Unfortunately it's very difficult to type it.

不幸的是,输入它非常困难。

#4


Underscore is the only one I can think of. You can put a few together like _$_.

Underscore是我唯一能想到的。你可以像_ $ _一样放几个。

Starting in JavaScript 1.5, you can use Unicode such as å.

从JavaScript 1.5开始,您可以使用诸如å之类的Unicode。

#5


Prototype uses $ and a $$. If you're using jQuery, you could use $$. However, unless its really well documented, this may be a bad idea--especially if someone else has to maintain this code after you've moved on.

Prototype使用$和a $$。如果你正在使用jQuery,你可以使用$$。但是,除非它有很好的文档,否则这可能是一个坏主意 - 特别是如果其他人必须在你继续前后维护这些代码。

#1


If you want a special variable like $ but $ is already taken by jQuery, why not use something that starts with $, like $a or similar? Just make sure it's one that jQuery doesn't also define.

如果你想要一个特殊的变量,比如$,但是jQuery已经采用了$,为什么不使用以$开头的东西,比如$ a或者类似的?只要确保它是jQuery也没有定义的那个。

#2


Unfortunately, older javascript supports letters, numbers, underscores, and $ in identifiers. In javascript 1.5 and later you can use Unicode characters, but that would be a very bad idea as they can be a pain to enter into most editors, and certainly aren't something you would want to have to type very often.

不幸的是,较旧的JavaScript支持字母,数字,下划线和$ in标识符。在javascript 1.5和更高版本中你可以使用Unicode字符,但这是一个非常糟糕的主意,因为它们可能很难进入大多数编辑器,当然也不是你想要经常打字的东西。

Source

#3


The one I like it best:

我最喜欢的那个:

λ = Function;

Unfortunately it's very difficult to type it.

不幸的是,输入它非常困难。

#4


Underscore is the only one I can think of. You can put a few together like _$_.

Underscore是我唯一能想到的。你可以像_ $ _一样放几个。

Starting in JavaScript 1.5, you can use Unicode such as å.

从JavaScript 1.5开始,您可以使用诸如å之类的Unicode。

#5


Prototype uses $ and a $$. If you're using jQuery, you could use $$. However, unless its really well documented, this may be a bad idea--especially if someone else has to maintain this code after you've moved on.

Prototype使用$和a $$。如果你正在使用jQuery,你可以使用$$。但是,除非它有很好的文档,否则这可能是一个坏主意 - 特别是如果其他人必须在你继续前后维护这些代码。