WTFJS¶
什么是吊鸡丝¶
有趣和棘手的JavaScript示例列表
JavaScript是一门伟大的语言。 它有一个简单的语法,庞大的生态系统,最重要的是一个伟大的社区。
与此同时,我们都知道JavaScript是一个非常有趣的语言,它有棘手的部分。 他们中的一些人可以迅速将我们的日常工作变成地狱,其中一些可以让我们大声笑出声来。
WTFJS最初的想法属于Brian Leroux. 这份名单受到了他的演讲 2012年dotJS上的“WTFJS”的启发:
Node包装手稿¶
你可以使用npm
来安装这本手册。
只要运行:
$ npm install -g wtfjs
你现在应该可以在命令行运行wtfjs
。
这将在您选择的$PAGER
中打开手册。
否则,你可以继续在这里阅读。
来源可在这里找到: https://github.com/denysdovhan/wtfjs
目录¶
- 💪🏻 Motivation
- ✍🏻 Notation
- 👀 Examples
[]
is equal![]
- true is false
- baNaNa
NaN
is not aNaN
- It's a fail
[]
is truthy, but nottrue
null
is falsy, but notfalse
document.all
is an object, but it is undefined- Minimal value is greater than zero
- function is not a function
- Adding arrays
- Trailing commas in array
- Array equality is a monster
undefined
andNumber
parseInt
is a bad guy- Math with
true
andfalse
- HTML comments are valid in JavaScript
NaN
is ~~not~~ a number[]
andnull
are objects- Magically increasing numbers
- Precision of
0.1 + 0.2
- Patching numbers
- Comparison of three numbers
- Funny math
- Addition of RegExps
- Strings aren't instances of
String
- Calling functions with backticks
- Call call call
- A
constructor
property - Object as a key of object's property
- Accessing prototypes with
__proto__
`${{Object}}`
- Destructuring with default values
- Dots and spreading
- Labels
- Nested labels
- Insidious
try..catch
- Is this multiple inheritance?
- A generator which yields itself
- A class of class
- Non-coercible objects
- Tricky arrow functions
arguments
and arrow functions- Tricky return
- Accessing object properties with arrays
Math.max()
less thanMath.min()
- Null and Relational Operators
Number.toFixed()
display different numbers- Comparing
null
to0
- Same variable redeclaration
- Other resources
- 🎓 License
💪🏻 动机¶
只是为了好玩
— “只是为了好玩: 一个意外革命家的故事”, Linus Torvalds
如果可能的话,这个清单的主要目标是收集一些疯狂的例子并解释它们是如何工作的。 只是因为学习之前我们不知道的东西很有趣。
如果您是初学者,可以使用这些笔记深入了解JavaScript。 我希望这些笔记能激励你花更多的时间阅读规范。
如果您是专业开发人员, 您可以将这些示例作为我们心爱的JavaScript的所有怪癖和意想不到的边缘的一个很好的参考。
无论如何,只要阅读这个。 你可能会找到新的东西。
✍🏻 符号¶
// ->
用于显示表达式的结果。
例如:
1 + 1 // -> 2
// >
意味着console.log
或其他输出的结果。
例如:
console.log('hello, world!') // > hello, world!
//
只是用于解释的评论
例:
// Assigning a function to foo constant const foo = function () {}
其他资源¶
- wtfjs.com — 一系列非常特殊的违规行为,不一致以及网络语言的简单痛苦不直观的时刻。
- Wat — 来自CodeMash 2012的Gary Bernhardt闪电谈话
- What the...JavaScript? — Kyle Simpsons谈论Forward 2尝试从JavaScript中“抽出疯狂”。他希望帮助您生成更干净,更优雅,更易读的代码,然后激励人们为开源社区做出贡献。