I've been a js developer for few years now. I've recently got into graphics / webgl programming and game engines etc. And no matter where I look, most code avoids the use of newer syntax such as () => {}
, let
, const
etc. Sticking almost exclusively to var
, function
callbacks etc. Even Promises seem to be absent from a lot of the examples I've seen in favour of callbacks.
Examples cited such as all of the three.js docs, the babylon.js docs, the stack.gl examples, pixi.js, phaser and most game code out there seem to all use thisold style code. Now, admittedly some of these frameworks are firaly mature now, but examples and features have been added since the newer syntax has become more common place.
Is there a particular reason for this? There are a few potential reasons I can think of (although can't confirm):
- Is var more heavily optimised in browsers? (I doubt it given that
const
comes with a degree of semantics as to it's usage and lifetime) and that arrow functions don't have athis
context. Admittedly, not everyone can use newer language features, but for code readability these add benefit, no? - Does using newer syntax and transpiling to older style take a hit in terms of optimisation? I'm basing this on the assumption that you don't exert as much control over final output. However, I would assume that most transpilation engines such as Babel etc are built with this in mind? However, Is it worthwhile avoiding as much transpilation as possible for graphics / game code in general?