3 ms·
I can be clearer if you need me to, but I think this is very common knowledge: the advice of "stick it in the constructor" abuses constructors and makes them do
by dvt 9y ago
I can be clearer if you need me to, but I think this is very common knowledge: the advice of "stick it in the constructor" abuses constructors and makes them do something they weren't meant to do. Incidentally, abusing constructors also sometimes breaks testing. Constructors (in virtually all languages) are notoriously difficult to test as is[1].
[1] https://stackoverflow.com/questions/14569499/javascript-mocking-constructor-using-sinon https://stackoverflow.com/questions/14569499/javascript-mock...
- davedx 9y agoYup... don't have side effects in constructors. That's the whole point of other lifecycle methods... this is a practice as old as C++
- danabramov 9y agoPlease note we are not suggesting side effects in constructors. I’m sorry if my previous comments gave you that impression. I elaborated here: https://news.ycombinator.com/item?id=16696836 https://news.ycombinator.com/item?id=16696836
- davedx 9y agoThanks for the clarification and for pitching in on this thread. FWIW I really appreciate the thought and effort the React team puts into changes.