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.

The WHY of WAT - understanding why 'JavaScript is Crazy'

82 pointsby amirhhzover 13 years ago

11 comments

rdtscover 13 years ago
&#62; ... he pokes fun at some apparently crazy behaviours in Ruby and Javascript.<p>I am sorry, but that still is crazy behavior. You can excuse it with a historical perspective ("well it had to hide errors from users") or by explaining "the why" like you do, that still doesn't make that behavior less crazy.
评论 #3518650 未加载
评论 #3518178 未加载
gamblerover 13 years ago
This is not "WHY", this is "HOW exactly". I bet the reason why JavaScript has these behaviors is due it being developed as a browser scripting language. Authors didn't want the entire script terminating because some part of it was buggy. This could have been handled by some clever isolation and error-recovery mechanism, but it wasn't. Probably due to time constraints.<p>These kinds of things are one of the reasons why I really don't like the idea of everything (including server-side and standalone apps) being written in JavaScript.
评论 #3518872 未加载
vmindover 13 years ago
This is only part of the why. The other part is the valueOf function which you can specify in order to control what the value of an object is when coerced.<p>So for instance:<p><pre><code> var arr1 = [1,2,3], arr2 = [1,2,3,4]; console.log(arr1 + arr2); // "1,2,31,2,3,4" arr1.valueOf = function () { return this.length; }; arr2.valueOf = arr1.valueOf; console.log(arr1 + arr2); // 7</code></pre>
bilalhusainover 13 years ago
text only cache, courtesy google: <a href="http://webcache.googleusercontent.com/search?q=cache:http://blog.caplin.com/2012/01/27/the-why-of-wat/&#38;hl=en&#38;strip=1" rel="nofollow">http://webcache.googleusercontent.com/search?q=cache:http://...</a><p>and a duckduckgo tip<p><pre><code> !cache http://blog.caplin.com/2012/01/27/the-why-of-wat/</code></pre>
评论 #3519865 未加载
shdonover 13 years ago
The original presentation was nicely done, but knowing how things work in JavaScript (even though I don't know Ruby) meant I didn't exactly have that WTF-experience. This article explains it nicely to those who had.
评论 #3517973 未加载
Achsharover 13 years ago
Well i'v never understood the problems with JavaScript but maybe it's because i haven't done things how other languages do it. But js is very "open" and bound free. Especially with functions and objects. They make sense to someone who is new to OOP. maybe its not follow how things are usually done in other languages but that does not mean its necessarily a bad thing. If you think something doesn't make sense that does not mean its wrong. i am learning c and i have to say typed variables must be faster but they are difficult to gasp at first. In fact its a nightmare to make variables of a certain type, it limits my thought process when i have to think what the variable's type is after every line of code. Strings look like a huge deal. The fact that i have to predetermine the length of a string is laughable. Its my string and it can be as long as i want it to be anywhere in my code. (yes i now sound immature but this is my experience until now, call it a rant if you may) Alot of things need to be known before we can write a meaningful program. Thats not the case with js or even with php to some extent.
评论 #3518373 未加载
评论 #3518530 未加载
评论 #3518770 未加载
评论 #3518557 未加载
bdgover 13 years ago
&#62;Error establishing a database connection<p>Does anyone have a mirror?
评论 #3518372 未加载
geraldalewisover 13 years ago
&#62; It can be a prefix ‘this number is positive’ operator where it operates on a single number.<p>`+` in this context is the "Unary + Operator" which coerces a value to a number via the internal `toNumber` method of the operand.<p>It doesn't make the number positive:<p><pre><code> node&#62; +-1 // -1</code></pre>
hcarvalhoalvesover 13 years ago
Automatic type coercion feels like a double-barreled shotgun, with one of the barrels pointed back at you:<p>0. Is only marginally useful 1. You have to be careful with what are you loading, and where 2. Will sooner or later blow up in your face
lognover 13 years ago
The syntax doesn't bug me too much. Most of it is documented fairly well. The craziest thing about JavaScript is a lack of any good online reference for their classes and methods. JavaScript documentation usually just resorts to a key example or a brief description without covering all the details.
评论 #3518141 未加载
评论 #3519302 未加载
onfocusinover 13 years ago
don't explain it! you are killing the fun...