Hmmm, interesting. That syntax without parentheses or assignment looks really weird. I tried it, but I can't seem to compile this code at all. I am using the presets "env", "react", and "stage-2"...
In that case arrowFunction is using the normal class method syntax. If that's what you meant, then yeah, the normal syntax puts the methods of the class in the prototype chain whereas using arrow functions with the "class properties" syntax appears not to. In the latter case, each instance will have its own copy of any such functions...
I tried running your code as-is in my browser and it didn't work. I also tried running it in node both as-is and transpiled with babel, and neither worked. Hopefully it isn't me having a stroke or something! :)
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.
Hmmm, interesting. That syntax without parentheses or assignment looks really weird. I tried it, but I can't seem to compile this code at all. I am using the presets "env", "react", and "stage-2"...
are you using babel? that's really odd, because it's vanilla ES syntax...
I think maybe you intended to put parentheses after
arrowFunction
, i.e:In that case
arrowFunction
is using the normal class method syntax. If that's what you meant, then yeah, the normal syntax puts the methods of the class in the prototype chain whereas using arrow functions with the "class properties" syntax appears not to. In the latter case, each instance will have its own copy of any such functions...I tried running your code as-is in my browser and it didn't work. I also tried running it in node both as-is and transpiled with babel, and neither worked. Hopefully it isn't me having a stroke or something! :)