04.01.2015, 05:44, "Rick Waldron" <[email protected]>:
On Sat Jan 03 2015 at 9:41:57 PM Alex Kocharin <[email protected]> wrote:Also, if you want to prevent mistakes like `object['blah' + symbol]`, linters could be changed to forbid/warn about concatenation inside property names.How would a linter know that `symbol` was actually a Symbol?
It wouldn't. But if it warns about string concatenation inside square braces (means, string + variable, but not number + variable), it should be good enough. This is the error the spec is trying to prevent, isn't it?
Of course, linter can't detect this:
var x = 'foo' + Symbol('bar')
object[x] = 123
But it will detect these existing errors:
var x = { foo: 'bar' }
object['foo' + x] = 123
I don't know what would have better error detection rate, but linter approach has two distinct advantages:
1. it allows to get a warning before compilation instead of crashing in runtime
2. it could be explicitly turned off when there is a false positive
Isn't good enough? Well, I'm sure some people will write JS-to-JS compilers that allow runtime type checking, maybe use TypeScript, which will prevent a lot of other similar bugs.
My point is: concatenating Symbols with other strings have legitimate uses. And _javascript_ shouldn't require any explicit type casting in order to do this, it isn't a statically typed language.
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

