TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

JavaScript cannot be fixed

3 点作者 horrido超过 9 年前

1 comment

alexkavon超过 9 年前
Absolutely agree. I was looking at this exact same thing last week. From what I&#x27;m come to understand from the overly bureaucratical responses I received from JavaScript community members, is that the language is designed with two intentions in mind:<p>1. Never break legacy code. 2. Be an open adaptable language that any developer from any background (or no background) can write code in.<p>It&#x27;s a messy messy attempt at being the popular kid. For example, classes, a popular new feature of ES6 looks like this:<p>~~~<p>class Hello {<p><pre><code> constructor(name) { this.name = name } hello() { return &#x27;Hello &#x27; + this.name + &#x27;!&#x27; }</code></pre> }<p>~~~<p>Cool. However in ES5, this is how a class is created:<p>~~~<p>function Hello(name) { this.name = name }<p>Hello.prototype.hello = function hello() { return &#x27;Hello &#x27; + this.name + &#x27;!&#x27; }<p>~~~<p>Okay...this makes sense and while the ES6 version is syntactically cleaner, it breaks the paradigm set in ES5. Knowing what I know of other languages, I&#x27;d expect something like this:<p>~~~<p>class Hello {<p><pre><code> function constructor(name) { this.name = name } function hello() { return &#x27;Hello &#x27; + this.name + &#x27;!&#x27; }</code></pre> }<p>~~~<p>I was told the reason is that methods are not functions. Which is an okay reason, but wait, they are functions in ES5...<p>Furthermore, you can&#x27;t use ES6 class syntax in non strict mode. At first I assumed a valiant attempt of deprecating older features, by requiring a strict mode as a sort of psuedo deprecation. However what stinks about this is that it still doesn&#x27;t fix the issue 100%. There are already too many tutorials out there describing how to write bad JS code. What ultimately needs to happen, is that browsers, nodejs, etc, need to always operate with strict parsing. The &quot;use strict&quot; flag is too easily forgotten. Yes this will break programs that are 50 years old, but everything has to come to a halt eventually. Another solution would be to &quot;fork&quot; or start a new language from scratch to replace it. I&#x27;m aware this is the intention of Dart, however it&#x27;s adoption rate seems too little to make an impact as evidence by it&#x27;s lack of care to be included in Chrome even (<a href="https:&#x2F;&#x2F;www.dartlang.org&#x2F;support&#x2F;faq.html#q-will-the-dart-vm-get-into-chrome" rel="nofollow">https:&#x2F;&#x2F;www.dartlang.org&#x2F;support&#x2F;faq.html#q-will-the-dart-vm...</a>).