什么是“@"ecmascript 6中的字符平均值

What does the "@" char mean in ecmascript 6?

本文关键字:字符 平均值 ecmascript quot 什么      更新时间:2023-09-26

给定下面的脚本,可以在angular 2官方教程中找到,"@"字符是什么意思?它是ecmascript 6的特性吗?

有人能详细说明一下吗?

import {Component} from 'angular2/core';
export class Hero {
  id: number;
  name: string;
}
@Component({
  selector: 'my-app',
  template:`
    <h1>{{title}}</h1>
    <h2>{{hero.name}} details!</h2>
    <div><label>id: </label>{{hero.id}}</div>
    <div>
      <label>name: </label>
      <input [(ngModel)]="hero.name" placeholder="name">
    </div>
    `
})
export class AppComponent {
  public title = 'Tour of Heroes';
  public hero: Hero = {
    id: 1,
    name: 'Windstorm'
  };
}

这只是TypeScript装饰器,请在这里查看

类装饰器是在类声明之前声明的。这个类decorator应用于类的构造函数,并且可以用于观察、修改或替换类定义。A级decorator不能在声明文件或任何其他文件中使用环境上下文(例如在声明类上)。

类decorator的表达式将在运行时,只使用装饰类的构造函数论点

如果类decorator返回一个值,它将替换该类具有提供的构造函数的声明。

注意:如果您选择返回一个新的构造函数,您必须小心维护原始原型。适用的逻辑运行时的decorator不会为您执行此操作。以下是应用于Greeter类的类装饰器(@sealed)示例:

@sealed
class Greeter {
    greeting: string;
    constructor(message: string) {
        this.greeting = message;
    }
    greet() {
        return "Hello, " + this.greeting;
    }
}