2 ms·
I wonder if it wouldn't have been better to just declare "javascript 2", and write a compiler from "javascript 1/legacy" to "javascript 2" in "javasript 2" -- a
by e12e 12y ago
I wonder if it wouldn't have been better to just declare "javascript 2", and write a compiler from "javascript 1/legacy" to "javascript 2" in "javasript 2" -- and suggest browsers/implementers used that.
I mean, do we really need both let and var; function * , function and => (I suppose having to mark a function as re-entrant at least one can understand, though)?
In the presentation, it's not clear (granted without commentary) why one would ever, for new code, write:
// Interpolate expressions into a template string
var name = "Bob",
time = "today";
console.log(`Hello ${name}, how are you ${time}?`);
function dedent(strings, ...values) {
let result = '';
for (let i = 0; i < strings.length; i++) {
result += strings[i].replace(/\n\s+/g, '\n') +
values[i];
}
return result;
}
console.log(dedent `Hello ${name},
How are you ${time}?`);
And not:
let name = "Bob",
time = "today";
console.log(`Hello ${name}, how are you ${time}?`);
let dedent = (strings, ...values) => { // is this valid?
let result = '';
for (let i = 0; i < strings.length; i++) {
result += strings[i].replace(/\n\s+/g, '\n') +
values[i];
}
return result;
}
console.log(dedent `Hello ${name},
How are you ${time}?`);
I understand backwards comparability, but for at least Firefox, let won't work without marking the code in question as v1.7 anyway. It might as well have been Self, Ruby or R6RS.
While having as compact syntax as Smalltalk or Lisp might be going a bit far in the other direction -- I do wish they'd taken the time to simplify the language.