TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Is JavaScript getting worse?

104 pointsby caisahover 10 years ago

18 comments

ajanuaryover 10 years ago
&gt; This means that typeof can now throw<p><pre><code> &gt;&gt;&gt; def f(): ... type(x) ... x = 10 ... &gt;&gt;&gt; f() Traceback (most recent call last): File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt; File &quot;&lt;stdin&gt;&quot;, line 2, in f UnboundLocalError: local variable &#x27;x&#x27; referenced before assignment irb(main):010:0&gt; def f() irb(main):011:1&gt; x.class irb(main):012:1&gt; x = 10 irb(main):013:1&gt; end =&gt; nil irb(main):014:0&gt; f() NameError: undefined local variable or method `x&#x27; for main:Object from (irb):11:in `f&#x27; from (irb):14:in `evaluate&#x27; from org&#x2F;jruby&#x2F;RubyKernel.java:1101:in `eval&#x27; from org&#x2F;jruby&#x2F;RubyKernel.java:1501:in `loop&#x27; from org&#x2F;jruby&#x2F;RubyKernel.java:1264:in `catch&#x27; from org&#x2F;jruby&#x2F;RubyKernel.java:1264:in `catch&#x27; from C:&#x2F;jruby-1.7.12&#x2F;bin&#x2F;jirb_swing:53:in `(root)&#x27; public class Test { public void f() { boolean isInt = x instanceof Integer; Integer x = 10; } } &gt;javac Test.java Test.java:3: error: cannot find symbol boolean isInt = x instanceof Integer; ^ symbol: variable x location: class Test 1 error </code></pre> Oh no, it&#x27;s now in line with just about every other lexically scoped language.
评论 #8873393 未加载
评论 #8873400 未加载
mmahemoffover 10 years ago
Whoop-dee-freakin’-doo???<p>Sure there&#x27;s a zillion frameworks and patterns for shoehorning OO into JavaScript. But the point is, ES6, is standardising it. That means libraries going forward will assume this is the way it&#x27;s done and build on top of it. It gives them more expressive power and better inter-op.<p>Also, default params are long overdue but I&#x27;m not sure that makes them &quot;so what&quot;. I&#x27;d rather avoid mangling the arguments array in some awkward if statements.<p>Bottom line, there&#x27;s a lot of things about JS that aren&#x27;t great, but it&#x27;s what all the browsers actually run so we&#x27;re kind of stuck with it and any improvements are welcome.<p>(Even if you use something like ClojureScript or CoffeeScript, JS is still the target language and the runtime. Improvements and standardisation matter.)
评论 #8873425 未加载
评论 #8873537 未加载
ahogeover 10 years ago
&gt;<i>Classes. Whoop-dee-freakin’-doo.</i><p>There are dozens of ways to do classes&#x2F;inheritance. Standardizing this means better tooling, documentation, and interoperability.<p>&gt;<i>Default parameters. By itself, this is another “so what” feature.</i><p>It&#x27;s extremely useful in conjunction with named parameters. Named parameters are so much better than &quot;option&quot; objects.<p>If it&#x27;s right in the function&#x27;s signature, you can see right away how this thing is supposed to be used. Since it&#x27;s declarative, it can be also picked up by your editor, too.<p>&gt;<i>let considered harmful</i><p>No, it&#x27;s not. It makes variable declaration work like everywhere else. Function scope is the super weird anomaly.
cronin101over 10 years ago
&gt; let considered harmful<p>Did people actually use the side-effect var-hoisting intentionally within their code?<p>Pretty much any JS style-guide worth its salt suggests manually moving var declarations to the top of scope since it&#x27;s nice to know ahead-of-time which indicators of state you should be keeping an eye on.<p>The idea of inspecting a variable that is later-on defined with let seems baffling to me. I can&#x27;t think of any reason why you would want to do this.
评论 #8873950 未加载
basicallydanover 10 years ago
&gt; let considered harmful: The problem with let is that it is not “hoisted” to the top of its block, as var is with its containing function.<p>Interesting point, but I disagree. I think that the lack of hoisting is one of the <i>benefits</i> of `let`. It works in a different way, which is more in line with other languages. Sometimes, you don&#x27;t want a bunch of variables at the top of your function. Many functions do not need to be executed in the way that hoisting makes easier.<p>By the way, quoting Betteridge’s law of headlines at the beginning of your article whose headline is a question does not mean you get a free pass of using such a headline ;)
gamesbrainiacover 10 years ago
This is one of the few posts about javascript that I&#x27;ve encountered that sees hoisting as a good thing. I like `let`.
评论 #8873301 未加载
评论 #8873398 未加载
评论 #8873343 未加载
评论 #8873736 未加载
评论 #8873620 未加载
phpnodeover 10 years ago
ES6 is fantastic and usable today using the excellent 6to5 [0]. I disagree with all of the author&#x27;s points, I think these are great features.<p>[0] <a href="https://github.com/6to5/6to5" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;6to5&#x2F;6to5</a>
collywover 10 years ago
Whats his problem with classes?<p>I find them a whole lot easier to reason about than prototype based inheritance. (But then I have more experience with class based languages).
评论 #8875067 未加载
评论 #8873408 未加载
评论 #8873556 未加载
评论 #8873476 未加载
robinduckettover 10 years ago
I like `let`. It means you have to be implicit and actually be aware of what you&#x27;re doing.
评论 #8873309 未加载
Hypxover 10 years ago
JavaScript is definitely getting better. The only question is whether they are changing too much too fast. There&#x27;ll be a lot of headscratchers when running into unfamiliar ES6 code.
cwmmaover 10 years ago
So classes in ES6 are something I have very mixed feelings about, on one hand all that is being added is syntactic sugar for what is already being done, I&#x27;d like to repeat that ES6 classes add NOTHING that isn&#x27;t already being done and all it really does is pave the cowpath that is being used in places like node<p>Currently:<p><pre><code> JSONParseStream.prototype = Object.create(Transform.prototype); function JSONParseStream(options) { Transform.call(this, options); ... } JSONParseStream.prototype = Object.create(Transform.prototype); Object.defineProperty(JSONParseStream.prototype, &#x27;constructor&#x27;, { value: JSONParseStream, enumerable: false, writable: true, configurable: true } JSONParseStream.prototype._transform = function(chunk, encoding, cb) { ... } </code></pre> With ES6:<p><pre><code> class JSONParseStream extends Transform { constructor(options) { super(options); ... }, _transform(chunk, encoding, cb) { ... } } </code></pre> That being said, the fact that previously you could not simply use the word class meant that despite efforts of people unused to the language (let me tell you how many half assed class libraries i&#x27;ve seen in code written by people who mainly code in python or java but have some web code as well), unnecessary inheritance tends to be avoided. The lack of a class keyword tends to get javascript writers to avoid inheritance for things best served by mix-ins or object literals, or whatever. I predict that adding the class keyword, while saving me some time will also cause an uptick to unnecessarily convoluted inheritance patterns as new users find they can implement all of their design patterns verbatim without thinking if they really need the ajax method, the json parser, and the url builder to all be in objects that inherit from each other.
arcatekover 10 years ago
I&#x27;m sorry, but I really see no point in this article.<p>Do you realize that if the optional arguments were not included in Function#length, you&#x27;d just be saying &quot;They are not reflected in the function’s length property. C&#x27;mon, man&quot; instead ?<p>Also, I don&#x27;t understand Whoop-dee-freakin’-doo.
评论 #8873291 未加载
Kiroover 10 years ago
I don&#x27;t understand the benefit of fat arrow. I actually think it decreases the readability. What does lexical &quot;this&quot; binding mean?
评论 #8873339 未加载
评论 #8873340 未加载
评论 #8873353 未加载
Mithalduover 10 years ago
Why didn&#x27;t they call &quot;spread&quot; by the same name it&#x27;s called virtually everywhere else, &quot;flatten&quot;?
评论 #8873727 未加载
JacobEdelmanover 10 years ago
Eh, a lot of the additions are improvements, a few are not, a very small few introduce some annoying features. It&#x27;s an improvement, maybe not perfect, but still a big improvement. Disclaimer: I like JavaScript.
filipncsover 10 years ago
<i>Best of all, proper tail calls</i><p>When are proper tail calls expected to show up? Looks pretty bleak.<p><a href="http://kangax.github.io/compat-table/es6/" rel="nofollow">http:&#x2F;&#x2F;kangax.github.io&#x2F;compat-table&#x2F;es6&#x2F;</a>
forthefutureover 10 years ago
I&#x27;m more interested by how many people still seem to be using typeof instead of toString. What are you doing for array checking since typeof array === &quot;object&quot;, !!x[0]?
评论 #8873579 未加载
jerrylucover 10 years ago
Betteridge&#x27;s law[1] strikes again.<p>[1] <a href="http://en.wikipedia.org/wiki/Betteridge%27s_law_of_headlines" rel="nofollow">http:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Betteridge%27s_law_of_headlines</a>
评论 #8873323 未加载
评论 #8873324 未加载