class Event extends Immutable.Record {
constructor(text) {
super({text: text, timestamp: Date.now()});
}
}
Calling new Event()
似乎返回一个构造函数:
new Event('started').toString()
“函数记录(值){ if(记录类型的值实例){ 返回
价值观;}
if(!(这个 RecordType 实例)){ return new RecordType(values);}
if(!hasInitialized){ hasInitialized=true; }变量
键=Object.keys(defaultValues); setProps(RecordTypePrototype,键);
RecordTypePrototype.size=keys.length; RecordTypePrototype._name=名称;
RecordTypePrototype._keys=键;
RecordTypePrototype._defaultValues=defaultValues;}
this._map=地图(值);}"
而调用该函数会返回预期的输出:
new Event('started')().toString()
“记录{“文本”:“开始”,“时间戳”:1453374580203}”
我究竟做错了什么?
不可变.记录”创建一个生成 Record 实例的新类.”,换句话说,它本身就是一个函数,您可以传递允许的键并返回一个可以扩展的类;
class Event extends Immutable.Record({text:'', timestamp:''}) {
constructor(text) {
super({text: text, timestamp: Date.now()});
}
}
> new Event('started').toString()
Event { "text": "started", "timestamp": 1453376445769 }
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)