javascript - If react sets this.id = XXX in the constructor, what is the use of this id?
过去多啦不再A梦
过去多啦不再A梦 2017-05-19 10:39:08
0
2
600

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

过去多啦不再A梦
过去多啦不再A梦

reply all(2)
淡淡烟草味

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() // 其实这里定义也就是给当前类,定义属性而已。便于后面在当前类里面使用。
曾经蜡笔没有小新

The usefulness depends on the person who writes the program. The React component itself does not have this attribute.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template