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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

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

82 点作者 amirhhz超过 13 年前

11 条评论

rdtsc超过 13 年前
&#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 未加载
gambler超过 13 年前
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 未加载
vmind超过 13 年前
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>
bilalhusain超过 13 年前
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 未加载
shdon超过 13 年前
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 未加载
Achshar超过 13 年前
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 未加载
bdg超过 13 年前
&#62;Error establishing a database connection<p>Does anyone have a mirror?
评论 #3518372 未加载
geraldalewis超过 13 年前
&#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>
hcarvalhoalves超过 13 年前
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
logn超过 13 年前
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 未加载
onfocusin超过 13 年前
don't explain it! you are killing the fun...