Ani*_*sad 2 ecmascript-6 reactjs
如何转换反应静态反应ES6
statics: {
getInstanceCount: (function() {
var count = 0;
return function() {
return ++count;
};
}())
}
Run Code Online (Sandbox Code Playgroud)
我在反应ES6中称之为
使用static关键字声明静态方法:
let count = 0;
class Foo {
static getInstanceCount() {
return ++count;
}
}
Run Code Online (Sandbox Code Playgroud)
如果要使用IIFE降低可见性count,您可以随后将静态方法分配给构造函数,就像任何其他属性一样:
class Foo {}
Foo.getInstanceCount = (function() {
var count = 0;
return function() {
return ++count;
};
}());
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
696 次 |
| 最近记录: |