javascript - JavaScript 中的 @ 是做什么用的?

标签 javascript mobx

我正在通读 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/

相关文章:

javascript - 验证 javascript 请求是否来自网站

javascript - 对 Mobx getDerivedStateFromProps 的误解

reactjs - 将 mobx 可观察对象作为 props 传递给 React 组件是否安全

javascript - 如何在加载下一页之前保持远程表单上的提交按钮处于禁用状态

javascript - 刷新页面时确保保持在同一 div 区域

javascript - Breeze 无法自动获取元数据

javascript - 这个数字是2的立方之和吗?

typescript - 处置 mobx @compulated react

firebase - 当错误模拟出现在 mobx-firebase-store 包中时,如何修复 "[mobx] deprecated: ` mobx.map` is deprecated"错误?

reactjs - React Mobx Firebase.onAuthStateChanged 监听器