Use of '@' in variables

9

I see in some languages that compile for javascript, like TypeScript and CoffeeScript, the use of @ in variables, as well as cases where it is not used. For example:

w = 10;
@v = 11;

In the end, what is the @ and what is the difference between using it and not?

    
asked by anonymous 19.04.2017 / 16:23

2 answers

7

In JavaScript, this does not mean anything, not even a valid variable identifier (such as $ or _ ).

In CoffeeScript, @ is the same as this . Only syntactic sugar .

In TypeScript, @ came from AtScript inheritance. In this case it is a decorator , the same as Python .

    
19.04.2017 / 16:48
3

They are decorators of functions and properties. When you use a decorator it adds or changes the shape with the function or property works.

Although they look like Java annotations and C # attributes , it does look even like the Python Decorator .

Only available from EcmaScript 6.

Proposed implementation of it which is where I have seen something more canonical about it.

    
19.04.2017 / 16:46