问题描述
给定一个ES6类,我如何检查它来确定其gettable静态属性和方法?在ES5中确定附加到类的静态(它是构造函数)就像迭代函数的属性一样简单。在ES6中,似乎有一些魔法不会让他们如此。
是的,所有的方法
Given an ES6 class, how can I inspect it to determine its gettable static properties and methods?
In ES5 determining the statics attached to a class (it's constructor) was as simple as iterating over the properties of the function. In ES6, is appears there is some magic going on that doesn't expose them as such.
Yes, all methods of class
es are non-enumerable by default.
You still can iterate them using Object.getOwnPropertyNames
. Filter out .prototype
, .name
and .length
(or just everything that is not a function). To include inherited static methods, you will have to walk the prototype chain explicitly (using Object.getPrototypeOf
).
这篇关于获取ES6类的静态列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!