我正在查看一些ES6代码,但我不明白将@符号放在变量前面时的作用。我能找到的最接近的事物与私有字段有关?
我在redux库中查看的代码:
import React, { Component } from 'react'; import { bindActionCreators } from 'redux'; import { connect } from 'redux/react'; import Counter from '../components/Counter'; import * as CounterActions from '../actions/CounterActions'; @connect(state => ({ counter: state.counter })) export default class CounterApp extends Component { render() { const { counter, dispatch } = this.props; return ( <Counter counter={counter} {...bindActionCreators(CounterActions, dispatch)} /> ); } }
这是我在该主题上找到的博客文章:https : //github.com/zenparsing/es-private-fields
在这篇博客文章中,所有示例都在类的上下文中-当在模块中使用符号时,这意味着什么?
是个 装饰工 。这是要添加到ECMAScript中的 建议 。以下是多个ES6和ES5等效的示例:javascript- decorators。
装饰器可以动态更改功能,方法或类的功能,而不必直接使用子类或更改要修饰的功能的源代码。
它们通常用于控制访问,注册,注释。