Npm 有人能解释一下es7反射元数据是关于什么的吗?

Npm 有人能解释一下es7反射元数据是关于什么的吗?,npm,ecmascript-6,jspm,systemjs,ecmascript-2016,Npm,Ecmascript 6,Jspm,Systemjs,Ecmascript 2016,我已经研究ES6、JSPM和angular2一周了,我发现了这个回购协议 如果我们查看底部脚本中的index.html,您将看到 System.import('reflect-metadata') .then(function() { return System.import('app/index'); }) .catch(console.log.bind(console)); 这是使用JSPM的systemjs polyfill来获取ES6的import 问题:在这种情

我已经研究ES6、JSPM和angular2一周了,我发现了这个回购协议

如果我们查看底部脚本中的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'
是一个针对ES7的提案包。它允许将元数据包含到类或函数中;本质上是这样

例如。 角度2 ES6:

@Component({selector: "thingy"})
@View({template: "<div><h1>Hello everyone</h1></div>"})
class Thingy{};
@组件({selector:“thingy”})
@视图({模板:“大家好”})
类Thingy{};
正如您所看到的,@Component和@View后面没有分号。这是因为它们本质上是类上的(元数据)链

现在让我们看一下Angular 2中的相同代码,但在ES5中:

function Thingy(){}
Thingy.annotations = [
    new angular.ComponentAnnotation({
        selector: "thingy"
    }),
    new angular.ViewAnnotation({

        template: "<div><h1>Hello everyone</h1></div>"
    })
];
函数Thingy(){}
Thingy.annotations=[
新的angular.ComponentAnnotation({
选择器:“thingy”
}),
新的angular.ViewAnnotation({
模板:“大家好”
})
];
正如您所看到的,@symbol抽象出了类的许多annotations属性,并使其更加复杂

更进一步,Angular团队知道注释对于新用户来说有点抽象。此外,ES5太冗长了。这就是为什么他们制作了
a.js
,这将使与注释的接口更好:


回答得很好。谢谢,什么是a.js?我的评论不长enough@gyozokudora.js是angular 2和es5的一个项目。似乎asif angular 2团队已经停止了这个项目。不确定index.html是什么意思,如果是,那么reflect metadata/reflect.js是一个增强的库:它有时在TypeScript编译器(tsc)抛出的代码中使用