Does the #39;@#39; symbol have special meaning in Javascript, Coffeescript or Jquery?(@ 符号在 Javascript、Coffeescript 或 Jquery 中是否有特殊含义?)
问题描述
我有一些看起来像的代码
I have some code that looks like
self = @
然后它使用 @someMethodName
或 self.someMethodName
@
有什么特殊含义吗?
推荐答案
@
不是 javascript 标识符的有效字符.标识符只能包含 $
、_
、数字和字母.
@
is not a valid character for a javascript identifier. Identifiers may only contain $
, _
, digits and letters.
在咖啡脚本中,@
表示 这个
.
In coffeescript, @
means this
.
CoffeeScript 有一些与 this 关键字相关的不错的功能.首先,CoffeeScript 使用 @ 符号作为这个的简写.例如,@foo 等价于 this.foo.其次,如果你使用@函数参数中的符号,CoffeeScript 将自动将这些值分配为对象的属性.
CoffeeScript has a few nice features related to the this keyword. First, CoffeeScript uses the @ symbol as shorthand for this.. For example, @foo is equivalent to this.foo. Second, if you use the @ symbol in the parameters of a function, CoffeeScript will automatically assign those values as properties of the object.
就 jQuery 而言,与 javascript 相同的标识符规则适用,因为 jQuery 只是 javascript.对于 jQuery 中 @
的其他用途,请参阅 this question 或 文档.
As far as jQuery is concerned, the same identifier rules as javascript apply since jQuery is just javascript. For other uses of @
in jQuery, see this question or the docs.
这篇关于'@' 符号在 Javascript、Coffeescript 或 Jquery 中是否有特殊含义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:'@' 符号在 Javascript、Coffeescript 或 Jquery 中是否有特殊含义?


- 如何向 ipc 渲染器发送添加回调 2022-01-01
- 从原点悬停时触发 translateY() 2022-01-01
- 在不使用循环的情况下查找数字数组中的一项 2022-01-01
- 为什么我的页面无法在 Github 上加载? 2022-01-01
- 为什么悬停在委托事件处理程序中不起作用? 2022-01-01
- 如何显示带有换行符的文本标签? 2022-01-01
- 是否可以将标志传递给 Gulp 以使其以不同的方式 2022-01-01
- 使用 iframe URL 的 jQuery UI 对话框 2022-01-01
- 我不能使用 json 使用 react 向我的 web api 发出 Post 请求 2022-01-01
- 如何调试 CSS/Javascript 悬停问题 2022-01-01