DEV Community

Discussion on: JS Symbol, what the heck?

Collapse
zyabxwcd profile image
Akash • Edited on

one question.
why did you write the last example as
class Computer {
constructor() {
this[Symbol.toStringTag] = "Computer";
}
}
and not like
class Computer {
[Symbol.toStringTag] = "Computer";
}

Collapse
romaintrotard profile image
Romain Trotard Author

I write like this because if I'm not mistaken the public class field will be available in ES2022.
Or we currently can use it thanks to babel plugin @babel/plugin-proposal-class-properties