我正在通读 MobX docs我对以下代码感到困惑:
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>
}
}
@符号的意义是什么?
最佳答案
它被称为装饰器,您可以在这里阅读所有相关信息:
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
关于javascript - JavaScript 中的 @ 是做什么用的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37334994/