DEV Community

naijadeveloper
naijadeveloper

Posted on

Questions πŸ™‹

  1. Does Es6 classes make function contructors obsolete? πŸ€” would you say "use a class instead" when you see me using a function constructor?

  2. Have you seen anyone use the bitwise operators? πŸ€” People hardly ever use those guys.

Top comments (7)

Collapse
 
anpos231 profile image
anpos231 • Edited

I'd say use ES6 classes. Sure the process of creating a class is slightly bigger than calling a function, but if you do it only sometimes, then there will be no difference for the performance, and you get much cleaner code.

Avoid creating new objects from classes inside loops though, calling a function is better in this case:

// Bad example
for (i=0; i < 1000; i++) {
  const c = new Something()
}
// Better example
for (i=0; i < 1000; i++) {
  const c = doSomething()
}

For all the other cases you are fine.

Collapse
 
naijadeveloper profile image
naijadeveloper

πŸ™‚πŸ™‚Thanks

Collapse
 
georgecoldham profile image
George
  1. Function constructors still have their place for now, but they are dying. They are going to be used for a very long time for compatibility reasons, although you may not see them too often in day to day work.

    • Side note: I would also discourage the use of classes, they are inefficient and many frameworks are starting the transition to move away from them (See React)
  2. I have only ever seen bitwise operators in hobby projects. That isnt to say that there isnt a use for them, but you are unlikely to ever need them.

Collapse
 
anpos231 profile image
anpos231

Only the process of creating new classes is costly.
So in case of react functional vs class based wont give you much difference, if you scripted your components properly.

Collapse
 
naijadeveloper profile image
naijadeveloper

yeah i have never used them, lol, i most times forget they exist.πŸ™‚ then i go over basics and i see them like "oh these guys"

Collapse
 
sudiukil profile image
Quentin Sonrel
  1. In my opinion: yes, given how "objects" work in ES6. In most cases both a class and function constructor will serve the same goal, the class syntax is just a bit closer to what you can find in other languages. Just my two cents though, there might be some differences I don't know of.

  2. Bitwise operators are indeed not that common but that's mostly because they are only useful in certain specific cases.

Collapse
 
naijadeveloper profile image
naijadeveloper
  1. yeap, class is more like a straightforward simpler way.

  2. just found thisπŸ™‚ talks about those guys.