3 ms·
Nobody really likes to talk about that time Perl and Javascript got drunk and hooked up.
by gorkish 3y ago
Nobody really likes to talk about that time Perl and Javascript got drunk and hooked up.
- jraph 3y agoIt happened at least twice. The first time, it gave jQuery, which notably inherited the $ and the terser syntax from perl. The second time, indeed, JS found Perl's "use strict" quite cute.
- gorkish 3y agoI disagree that jquery adopted anything from perl. jQuery's $ is not a sigil.
- lifthrasiir 3y agoIt was originally `use strict` without any quotes, along with other possible `use ...` statements in the scrapped ES4 working draft. It seems that the exact person suggested this particular syntax was David-Sarah Hopwood [1], which suggestion was quickly adopted to the next draft of what eventually became ES5. [1] https://web.archive.org/web/20150525070848/https://mail.mozilla.org/pipermail/es5-discuss/2009-May/002591.html https://web.archive.org/web/20150525070848/https://mail.mozi...
- jraph 3y agoIt was good that it's a string literal, so it did not make the file incompatible with parsers that didn't support strict mode. You'd have to make sure your code behaved correctly both in sloppy mode and in strict mode. Probably irrelevant today.
- lifthrasiir 3y agoThat indeed was a big concern, and the initial proposal assumed that it at least has to survive the lexical analysis. At some point there were two syntaxes, `use strict` (optionally followed by a comma and other tokens) or `if (false) use(strict)` at one's choice. In comparison Hopwood's proposal was not even an actual proposal but quickly adopted due to its simplicity and robustness. The only complaint was a space in the literal.
- jackjkal 3y agoAt least Perl "uses" `use` for more things than just strict mode. As a beginner, I remember finding this magical literal that (might) alter JS behavior pretty strange, especially since there were no other `use` directives. I really like Perl's `use diagnostics` directive, which provides more verbose error messages, and am frankly surprised a far more popular language that is supposed to be beginner-friendly does not have something similar.