What is @ used for JavaScript?

I am reading MobX docs , and the following code confuses me:

class Todo { id = Math.random(); @observable title = ""; @observable finished = false; } @observer class TodoListView extends Component { render() { return <div> <ul> {this.props.todoList.todos.map(todo => <TodoView todo={todo} key={todo.id} /> )} </ul> Tasks left: {this.props.todoList.unfinishedTodoCount} </div> } } 

What is the meaning of the @ symbol?

+6
source share
1 answer

It is called a decorator, you can read all about it here:

https://github.com/wycats/javascript-decorators

Decorator:

  • expression that evaluates a function that takes the target, name and descriptor of the decorator as arguments and, if necessary, returns a descriptor of the decorator to be installed on the target object
+3
source

All Articles