Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
88
rated 0 times [  92] [ 4]  / answers: 1 / hits: 19036  / 12 Years ago, thu, january 3, 2013, 12:00:00

I have some code that looks like


self = @

and then later on it's using @someMethodName or self.someMethodName


Does @ have some special meaning?


More From » jquery

 Answers
32

@ is not a valid character for a javascript identifier. Identifiers may only contain $, _, digits and letters.



In coffeescript, @ means this.




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.




Edit: 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.


[#81102] Wednesday, January 2, 2013, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
devonw

Total Points: 311
Total Questions: 116
Total Answers: 111

Location: Senegal
Member since Fri, Aug 21, 2020
4 Years ago
;