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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

WTF does this code do?

10 点作者 benvan大约 11 年前

6 条评论

sigvef大约 11 年前
This is why you should always use semicolons in JavaScript. Omitting semicolons here turns this:<p><pre><code> var angry = say(&#x27;Garrrr!&#x27;) &#x2F;&#x2F; what should I say? (amIHappy ? happy : angry)() </code></pre> into this:<p><pre><code> var angry = say(&#x27;Garrrr!&#x27;)(amIHappy ? happy : angry)()</code></pre>
zequel大约 11 年前
Most web browsers (if you&#x27;re running this code in a web browser), will do ASI (automatic semicolon insertion).<p><a href="http://jsfiddle.net/CxUXh/" rel="nofollow">http:&#x2F;&#x2F;jsfiddle.net&#x2F;CxUXh&#x2F;</a> works fine in Chrome, changing the console.log to an alert.<p>Not that I&#x27;m advocating omitting semicolons!
评论 #7460007 未加载
dsschnau大约 11 年前
Does it return that because `say` isn&#x27;t defined inside its own function definition, so it evaluates as false?
TophWells大约 11 年前
It doesn&#x27;t seem to do anything.
rainmaking大约 11 年前
Hahaha, nice!<p>I&#x27;m getting a linter.
dismal2大约 11 年前
this is idiotic