Live data from Hacker News

A Strong Mode for JavaScript

docs.google.com

1–10 of 45 posts

Re: A Strong Mode for JavaScript

#5

It is a SyntaxError to use the identifier ‘eval’. SyntaxError? "use strong"; should probably do something like: let eval = void 0; rather than making eval a SyntaxError.

Making it a syntax error means code will not fail quietly. This should help transition code to Strong mode.

Re: A Strong Mode for JavaScript

#6
post #2

> It is a SyntaxError to use the keyword 'var' What if I want a variable?!

use `let ` or `const `. there's no need to use `var` in ES6+, ever.

But we're going to keep it around, aren't we? Because we can always add features but we can't really remove them. It feels like JS is getting cruftier. Would it be better if var already worked like let? Sure. Will JS be better with two slightly different ways of scoping a variable, one of which you really shouldn't use? Doesn't seem like it. One more thing to explain to newcomers.

Re: A Strong Mode for JavaScript

#7

It is a SyntaxError to use the identifier ‘eval’. SyntaxError? "use strong"; should probably do something like: let eval = void 0; rather than making eval a SyntaxError.

Making it a syntax error means code will not fail quietly. This should help transition code to Strong mode.

Wouldn't a `ReferenceError` make more sense?

Re: A Strong Mode for JavaScript

#8

Earlier quoted context omitted.

use `let ` or `const `. there's no need to use `var` in ES6+, ever.

But we're going to keep it around, aren't we? Because we can always add features but we can't really remove them. It feels like JS is getting cruftier. Would it be better if var already worked like let? Sure. Will JS be better with two slightly different ways of scoping a variable, one of which you really shouldn't use? Doesn't seem like it. One more thing to explain to newcomers.

Well, for newcomers we can either bring them up using `let` exclusively or the explanation of function scope can include a footnote on `let` versus `var`.

Re: A Strong Mode for JavaScript

#9
I think I like most of what this document proposes except for the following:

  In strong code, accessing objects (strong or not) throws on missing properties.
  New object properties have to be defined explicitly and cannot be removed
  from strong objects.
To me, this seems to break a fundamental aspect of the language. I've found it very acceptable to be able to define an object literal property "on the fly." However, with strong mode trying to make the language friendlier to eventually being more statically typed, I see the necessity. It just boggles my dynamically typed mind :-)

Re: A Strong Mode for JavaScript

#10

I think I like most of what this document proposes except for the following: In strong code, accessing objects (strong or not) throws on missing properties. New object properties have to be defined explicitly and cannot be removed from strong objects. To me, this seems to break a fundamental aspect of the language. I've found it very acceptable to be able to define an object literal property "on the fly." However, wi…

Being able to do

  foo = bar.x || 3;
rather than

  foo = bar.hasOwnProperty('x') ? bar.x : 3;
is nice.
Post reply on HN