People are used to use all kind of "tricks" in Javascript.
constsqr=(x)=>x*xconsole.log(sqr(3))
Everybody knows, this defines a function, but WHY do we use a language, that states to define a constant, but creates a function instead? Why does a language allow to use this kind of ambiguity?
There are a lot of good reasons, why things are a bit wiered in JS, but not everybody is happy to use a language like a shell game. Classes make Javascript more explicit. If you define a class using the CLASS-keyword, everybody will know your intention. This is often not the case with common Javascript code...
CEO of developer educational nonprofit Playful Programming, I do development of all kinds, usually focusing on web development.
I collect retro video games 🎮, like reading 📖, love teaching 👨🏫
I mean, I'm on board with the class keyword. This wasn't a slam piece, it was to help folks understand historical context of the language and maybe even understand the prototype system better
Of course, thank you very much for your effort. I just wanted to note, that it is not a advantage to define a class without using the keyword. Even if it was only "syntactical shugar" (which i think it is not), it is better to use a clear naming for things you do.
We should always be clear that a programming language is made for programmers, not for computers. A computer uses opcodes, so in that case we should use assembler.
Because otherwise Corbin instance is not a member of Corbin constructor if you will use instanceof for check...
Seems there is a non-enumerable .constructor property in Corbin.prototype, accordingly with the specification, which is then used for matching instanceof. And when you just re-assign ... you deleting it.
And for sure instead of code above you may also go like this:
People are used to use all kind of "tricks" in Javascript.
Everybody knows, this defines a function, but WHY do we use a language, that states to define a constant, but creates a function instead? Why does a language allow to use this kind of ambiguity?
There are a lot of good reasons, why things are a bit wiered in JS, but not everybody is happy to use a language like a shell game. Classes make Javascript more explicit. If you define a class using the CLASS-keyword, everybody will know your intention. This is often not the case with common Javascript code...
I mean, I'm on board with the
classkeyword. This wasn't a slam piece, it was to help folks understand historical context of the language and maybe even understand the prototype system betterOf course, thank you very much for your effort. I just wanted to note, that it is not a advantage to define a class without using the keyword. Even if it was only "syntactical shugar" (which i think it is not), it is better to use a clear naming for things you do.
We should always be clear that a programming language is made for programmers, not for computers. A computer uses opcodes, so in that case we should use assembler.
IMO computer languages are made for computers, - not for programmers. When you start realize it, programming will make easier.
Sy, why do we not use assembler? It is much easier to understand for a computer...
Mostly we use heavy-weight frameworks which finally generate assembler/machine code for computers, not for you.
I always knew that classes in JS are just syntactic sugar.
No!
JS classes are not “just syntactic sugar” | by Andrea Giammarchi | Medium
Andrea Giammarchi ・ ・
webreflection.Medium
Classes, Not Just Syntactic Sugar
Parwinder 👨🏻💻 ・ Sep 4 '20 ・ 3 min read
Class is not just a Syntactic sugar in Javascript | by Arun Rajeevan | Medium
Arun Rajeevan ・ ・
arunrajeevan.Medium
I always convert JS classes into prototype chains without any consequences.
Please fix the error of re-assigning Corbin.prototype, instead of :
much better do the following:
Because otherwise Corbin instance is not a member of
Corbinconstructor if you will useinstanceoffor check...Seems there is a non-enumerable
.constructorproperty inCorbin.prototype, accordingly with the specification, which is then used for matchinginstanceof. And when you just re-assign ... you deleting it.And for sure instead of code above you may also go like this: