'@' 符号在 Javascript、Coffeescript 或 Jquery 中是否有特殊含义? [英] Does the '@' symbol have special meaning in Javascript, Coffeescript or Jquery?

查看:20
本文介绍了'@' 符号在 Javascript、Coffeescript 或 Jquery 中是否有特殊含义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些看起来像的代码

I have some code that looks like

self = @

然后它使用 @someMethodNameself.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 中是否有特殊含义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆