[英]What is the @ used for in JavaScript?
I'm reading through the MobX docs and I'm confused by the following code: 我正在阅读MobX文档 ,我对以下代码感到困惑:
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 significance of the @ symbol? @符号的意义是什么?
It's called a decorator, you can read all about it here: 它被称为装饰器,你可以在这里阅读所有相关内容:
https://github.com/wycats/javascript-decorators https://github.com/wycats/javascript-decorators
A decorator is:
装饰者是:
- an expression that evaluates to a function that takes the target, name, and decorator descriptor as arguments and optionally returns a decorator descriptor to install on the target object
一个表达式,其值为一个函数,该函数将目标,名称和装饰器描述符作为参数,并可选择返回装饰器描述符以在目标对象上安装
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.