For example, the id here, why is it defined like this? I see there is no such definition on the Internet, or I can't find it. Please answer. If there is a relevant link, please provide a link. Thank you all
淡淡烟草味2017-05-19 10:41:08
Setting properties in the constructor has no special meaning.
If this writing method is not ES6, it will be easier for you to understand.
function Parent(){
this.id = +new Date()
}
Parent.prototype.getId = function(){
console.log(this.id)
}
var p = new Parent()
p.getId() // 其实这里定义也就是给当前类,定义属性而已。便于后面在当前类里面使用。
曾经蜡笔没有小新2017-05-19 10:41:08
The usefulness depends on the person who writes the program. The React component itself does not have this attribute.