I didn’t get very well your explanation about arrow functions, although your point is don’t use it inside a class cause it has no scope and it will be recreated every time, right?
Usually the easiest and proper way to do so is with the prototype as all changes to the Object prototype object are seen by all objects through prototype chaining.
newB().handleClick();// Uncaught TypeError: (intermediate value).handleClick is not a functionnewB().handleLongClick();// A.handleLongClick// B.handleLongClick
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Thank you for the article, insightful. :-)
I didn’t get very well your explanation about arrow functions, although your point is don’t use it inside a class cause it has no scope and it will be recreated every time, right?
Thank you!
Apart from recreation of the function itself it has other drawbacks too.
Let me give you two examples, first let's say you have a class with an arrow function and when testing you want to mock it:
Usually the easiest and proper way to do so is with the prototype as all changes to the
Object
prototype object are seen by all objects through prototype chaining.But in this instance:
A.prototype.handleLongClick
is defined.A.prototype.handleClick
is not a function.Same happens with inheritance:
Then: