符号(@)在ES6 javascript中有什么作用? (ECMAScript 2015) [英] What does the at symbol (@) do in ES6 javascript? (ECMAScript 2015)

查看:449
本文介绍了符号(@)在ES6 javascript中有什么作用? (ECMAScript 2015)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在查看一些ES6代码,我不明白@符号放在变量前面时的作用。我能找到的最接近的东西与私有字段有关吗?

I'm looking at some ES6 code and I don't understand what the @ symbol does when it is placed in front of a variable. The closest thing I could find has something to do with private fields?

我从 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

Here is a blog post I found on the topic: https://github.com/zenparsing/es-private-fields

在这个博客文章中,所有的例子都在一个类的上下文中 - 当在模块中使用符号时它意味着什么?

In this blog post all the examples are in the context of a class - what does it mean when the symbol is used within a module?

推荐答案

这是一个装饰者。将提案添加到ECMAScript中。有多个ES6和ES5等效示例: https://github.com/wycats/javascript-decorators

It's a decorator. It's a proposal to be added to ECMAScript. There are multiple ES6 and ES5 equivalent examples on: 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.

它们通常用于控制访问,注册和注释。

They are commonly used to control access, registration, annotation.

这篇关于符号(@)在ES6 javascript中有什么作用? (ECMAScript 2015)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆