14 ms·
It does not. Certain frameworks will encourage more of its use (such as with passing functions-as-props in React), but Javascript itself can support multiple p
by dentemple 9y ago
It does not.
Certain frameworks will encourage more of its use (such as with passing functions-as-props in React), but Javascript itself can support multiple paradigms, with the `this` keyword supporting only some of its messiest parts.
- paulgb 9y agoIs this true even with classes defined with the "class" keyword? I just tried it and I can't access fields without "this."
- austincheney 9y agoClasses are a relatively new feature to the language and certainly aren't required. Classes are a bit troublesome in that lexical scope doesn't directly apply to class parameters, which is why class parameters cannot achieve explicit privacy unlike other references in the language.
- paulgb 9y agoRight, I was referring to ES6 classes because that's what the article specifically refers to.
- dragonwriter 9y agoThe “class” keyword was added fairly recently to simplify Java-style OO programming in JavaScript; it's true that that style of programming requires extensive use of “this” in JS, specifically because, unlike Java, JavaScript is not designed from the ground up to favor that style exclusively. Java will probably always be a better language for writing Java than JavaScript is, but the Java-in-browsers story has sucked for a long time, so we’re stuck with people who want Java using JavaScript as Java.
- heavenlyblue 9y agoSo how is JavaScript supposed to be used then?
- LaGrange 9y agoReluctantly.
- austincheney 9y agoIt is supposed to be used with a solid understanding of its scope model, which unlike OOP is not an avoidable quality.