符号(@)在ES6 javascript中有什么作用? (ECMAScript 2015)
作者:互联网
我正在查看一些ES6代码,我不明白@符号放在变量前面时的作用.我能找到最接近的东西与私人田地有关?
我从redux library看的代码:
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等效示例:https://github.com/wycats/javascript-decorators
Decorators dynamically alter the functionality of a function, method, or class without having to directly use subclasses or change the source code of the function being decorated.
它们通常用于控制访问,注册,注释.
标签:ecmascript-next,javascript,reactjs 来源: https://codeday.me/bug/20190916/1808671.html