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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

What's wrong with JavaScript

43 点作者 rdallasgray将近 12 年前

12 条评论

coldtea将近 12 年前
I&#x27;d rather have a fixed JS (no BS coercion, actual hashes, method_missing, better binding rules, local vars by default, &quot;use scrict&quot; checks for everything, int64 arithmetic, and a non manual ad-hoc way to create prototype chains) as the next version, instead of the &quot;backwards compatible&quot; pile-on that the upcoming version is.<p>Such a JS would enable them to reuse large parts (or the entirety) of the current interpreters&#x2F;JITs, just as well as the next ECMAScript, but would also fix most BS and enable further performance improvements.<p>That is, what I propose, would be a slightly incompatible release, say: &quot;JavascriptFixed&quot;.<p>As for backwards-compatibility, this would be played out in two ways. Transpilers (like Coffescript) could convert &quot;JavascriptFixed&quot; to Javascript, and people could use the script tag to denote the presence of &quot;JavascriptFixed&quot;.<p>Given vendor support, the familiar syntax, and the performance improvements, it could take over JS in 4-5 years. No we&#x27;ll have decade or more until the whole mess that&#x27;s the next version becomes popular, and we&#x27;ll still have the whole JS mess, just swept under the carpet.
评论 #5851824 未加载
评论 #5851980 未加载
评论 #5851283 未加载
omegote将近 12 年前
&quot;What&#x27;s wrong with JavaScript&quot; and just a single block of JavaScript was found in that post. The rest, CoffeeScript.
bliker将近 12 年前
I agree with click event (and others) are real pain. But absence of _missing is more personal preference. Major problem of javascript it the time that it takes to implement new features into the language that can sometimes converge to infinity.<p>Also I would be grateful if articles about javascript would feature javascript instead of CoffeeScript.
ahoge将近 12 年前
Dart fixes all of JavaScript&#x27;s &quot;WAT&quot; quirks. There is proper lexical scoping, a lexically scoped `this`, no type coercion, no monkey-patching, and so forth. It also has a &quot;method_missing&quot; thing called &quot;noSuchMethod&quot;.<p>But most importantly: It scales.<p>Structure is declared and not imperatively constructed. Your tools can tell what&#x27;s going on without actually running the code.
shtylman将近 12 年前
This post is not javascript, it is coffeescript. Stop confusing the two.
评论 #5851515 未加载
peter_l_downs将近 12 年前
&gt; the scoping is wacky (and the var trap is a disaster);<p>Read <a href="http:&#x2F;&#x2F;bonsaiden.github.io&#x2F;JavaScript-Garden&#x2F;#function.scopes" rel="nofollow">http:&#x2F;&#x2F;bonsaiden.github.io&#x2F;JavaScript-Garden&#x2F;#function.scope...</a>, be enlightened
评论 #5851316 未加载
评论 #5850999 未加载
评论 #5851042 未加载
ancarda将近 12 年前
And yet nobody seems to be interested in Dart.
评论 #5853992 未加载
评论 #5851389 未加载
frozenport将近 12 年前
Most of Javascript feels like a kludge and my keyboard&#x27;s &#x27;T&#x27;,&#x27;H&#x27;,&#x27;I&#x27;,&#x27;S&#x27; keys need to be replaced every week or two. I always ponder, what if instead of JavaScript we had Java?
评论 #5850971 未加载
评论 #5851027 未加载
danbruc将近 12 年前
The biggest weakness is missing - it is not statically typed.
评论 #5853991 未加载
sanderjd将近 12 年前
Oops, I think the author meant to have <i>copy[key] = val</i> for the last line of this example:<p><pre><code> copyObject: (inputObject) -&gt; copy = [] for key, val of inputObject copy.key = val </code></pre> As written, it uselessly sets a bunch of values to the <i>key</i> property in turn.<p>The point stands though.
warfangle将近 12 年前
Rename to &quot;what&#x27;s wrong with coffeescript&quot; and this blog post might approach accuracy.
wwweston将近 12 年前
&quot;&gt;thing: -&gt; &gt; @_thing ?= new Thing<p>..is … irritating.&quot;<p>So... having one sigil to distinguish a class variable isn&#x27;t irritating, but another for a variable accessed by an accessor method is. Got it.<p>&gt; It’s tempting to presume that this is a ‘feature’ of prototypal inheritance<p>Why would this be tempting? As the author points out, there are prototype-based languages that avoid it, and you could remove prototypes from JavaScript and still encounter the issue.<p>&gt; we’re not writing Java. We’re in a highly dynamic language. We want nice things. Or, we could create setters and getters using the new ES5 syntax – but that’s not available everywhere (pre-IE9, for instance), and, I would argue, is too unwieldy to apply as a rule.<p>You want an easy way to create accessors? OK:<p><pre><code> function prop(name,gNs) { function undef(v) { return typeof v == &#x27;undefined&#x27;; } var _name = &#x27;_&#x27; + name, get = gNs &amp;&amp; gNs.get, set = gNs &amp;&amp; gNs.set; if(get &amp;&amp; set) return function (x) { return undef(x) ? get.call(this,this[_name]) : (this[_name] = set.call(this,x), this); } if(get &amp;&amp; !set) return function (x) { return undef(x) ? get.call(this,this[_name]) : (this[_name] = x, this); } if(!get &amp;&amp; set) return function (x) { return undef(x) ? this[_name] : (this[_name] = set.call(this,x), this); } return function (x) { return undef(x) ? this[_name] : (this[_name] = x, this); } } </code></pre> You&#x27;re welcome. Use it like so:<p><pre><code> obj = { thing: prop(&#x27;thing&#x27;) } </code></pre> when you want your accessors to do something other than getting&#x2F;setting:<p><pre><code> obj = { thing: prop(&#x27;thing&#x27;, { get: function () { return foobarled(this._thing); }, set: function (x) { this._thing = unfoobarled(x); } }) } </code></pre> &gt; What we’re really saying is ‘everything is a hashtable’. Is that a good thing?<p>I&#x27;m more sympathetic to this criticism. There&#x27;s times when the fact that everything can have arbitrary properties is convenient, but it does place some burden on the developer to pay attention.<p>Then again, I think that&#x27;s a general charge to which any highly dynamic language is going to have to answer on some point or another. And if you&#x27;re prone to typing `[]` when you mean `{}` (understandable if you&#x27;ve come from a language where they have different meanings), it&#x27;s possible you should do the more conspicuous thing and use `new Array` and `new Object` instead.<p>&gt; Nothing is an object<p>No. What the author is really talking about that by default, there aren&#x27;t &quot;methods&quot; with class-bound scope. Just functions whose `this` scope is dynamic but does live by some pretty understandable rules.<p>&gt; _missing<p>Missing method&#x27;s sometimes convenient, and there are occasions when I miss it in JS too, but it&#x27;s much rarer than I once would have thought. Use cases in languages where functions are less often let out on their own tend to get taken care of differently in languages where they do.<p>&gt; I’ve yet to hear anyone convincingly argue that JavaScript’s version of OOP offers anything in addition to or distinction from more traditional versions;<p>&quot;convincingly&quot;<p>Convincing who?
评论 #5853948 未加载