scr*_*key 7 typescript ecmascript-6 angular
有谁能告诉我.'@'导入的Component函数前面的符号.这是ES6语法吗?我没有看到它用于我看过的任何其他非角度ES6项目.
import {Component} from ...
@Component({})
Run Code Online (Sandbox Code Playgroud)
Hug*_*ois 18
该@语法是ES7一个新的草案这是目前在阶段1(提案阶段)的一部分.他们被称为装饰者.
装饰器使得可以在设计时注释和修改类和属性.
有关更多信息,请参阅:https://github.com/wycats/javascript-decorators
注意:您可以使用装饰器,通过启用(在webpack中)或通过将配置设置为使用Babeloptional[]=es7.decoratorsstage:1
仅针对记录,只需将TypeScript注释转换为以下内容,即可在ES6中实现相同的行为:
import {Component, ...} from 'angular2/core';
export class myAppOrDirective {
static get annotations() {
return [
new Component({
selector: 'my-app-or-directive'
}),
new View({
template: `<div>Hello!</div>`
})
];
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1525 次 |
| 最近记录: |