Hacker News new | past | comments | ask | show | jobs | submit login

They run into enough problems with objectness just learning map / filter / reduce. I've seen so many angry / frustrated students trying to use a for each loop to iterate over an Array only to find that although this works in most languages, in js these just loop over the fucking KEYS of the object (which now opens up the discussion about how `obj[1]` is not a key but `obj['hey']` is a key and the differences therein.



I wonder if there would be a market for a "stricter mode" version of JavaScript that simply does not allow you to use the legacy features that are so quirky.

Eg just disallow for...in to be used at all (but allow for...of)

No iterating over objects except via eg Object.entries

No inheriting objects from other objects (ie no prototypal inheritance)

No var

No anonymous functions (ie only named function declarations or lambda/fat-arrow expressions, to avoid `this` binding gotchas)

Etc

I think the only real big blocker to a thing like this is that it'd need tooling (eg a transpiler that injects error throws at appropriate places), and tooling is another big hairy thing that makes JS less approachable for beginners.


> I wonder if there would be a market for a "stricter mode" version of JavaScript that simply does not allow you to use the legacy features that are so quirky.

It's almost like we could use a better frontend language. Too bad there isn't some magical universal assembly language supported by all major browsers we could use as a launchpad for such a thing ;)


That's something which can be done at build time, such as through a linter.


Some of it would need to be runtime checks to be fully consistent and unsurprising, I think.


I haven't tried it, but somewhere in that neighborhood: https://github.com/endojs/Jessie


these should be expert mode only features that have to be unlocked as opposed to default. So easy to shoot yourself in the foot. Kinda fun if you've been doing it for a while though.


Kind of crazy that nobody taught them to use "for of" instead of "for in". Maybe make a linter that marks "for in" as a syntax error




Consider applying for YC's W25 batch! Applications are open till Nov 12.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: