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 中是否有特殊含义?


基础教程推荐
- Bootstrap 模态出现在背景下 2022-01-01
- Bokeh Div文本对齐 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01