一直在研究ES6,JSPM& angular2一周了,我发现了这个回购ES6-loader
如果我们查看底部脚本中的index.html,您会看到
System.import('reflect-metadata')
.then(function() {
return System.import('app/index');
})
.catch(console.log.bind(console));
这是使用JSPM的systemjs polyfill获取ES6的import
。
问题:在这种情况下,reflect-metadata真的有什么作用? npm reflect-meta我阅读的文档越多,我就越不了解它的作用吗?
答案 0 :(得分:46)
c:\Windows>icacls Temp
Temp NT AUTHORITY\SYSTEM:(OI)(CI)(S,RD)
BUILTIN\IIS_IUSRS:(OI)(CI)(S,RD)
BUILTIN\Users:(CI)(S,WD,AD,X)
BUILTIN\Administrators:(F)
BUILTIN\Administrators:(OI)(CI)(IO)(F)
NT AUTHORITY\SYSTEM:(F)
NT AUTHORITY\SYSTEM:(OI)(CI)(IO)(F)
CREATOR OWNER:(OI)(CI)(IO)(F)
是一个针对ES7的提案。它允许将元数据包含在类或函数中;基本上是syntax sugar。
实施例。 Angular 2 ES6:
'reflect-metadata'
正如您所看到的,在@Component和@View之后没有分号。这是因为它们本质上是类的(元)数据的链。
现在让我们看看Angular 2中的相同代码,但是在ES5中:
@Component({selector: "thingy"})
@View({template: "<div><h1>Hello everyone</h1></div>"})
class Thingy{};
正如您所看到的,@符号抽象出了很多类的注释属性,并使其更加D.R.Y。
更进一步,Angular团队知道注释对于新用户来说有点抽象。而且,ES5太冗长了。这就是为什么他们使function Thingy(){}
Thingy.annotations = [
new angular.ComponentAnnotation({
selector: "thingy"
}),
new angular.ViewAnnotation({
template: "<div><h1>Hello everyone</h1></div>"
})
];
能够更好地与注释接口: