在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
当前回答
在JavaScript中:
2 == [2]
//更陌生 2 == [[[2]]]
//和彻头彻尾的坚果 Var a = {"abc": 1}; A [[[["abc"]]]] === A ["abc"];//这也是正确的
幸运的是,stackoverflow.com网站上善良的人们向我解释了这一切:http:/stackoverflow.com/questions/1724255/why-does-2-2-in-javascript
其他回答
VBScript的日期/时间文字(为什么这个仍然如此罕见?):
mydate = #1/2/2010 5:23 PM#
If mydate > #1/1/2010 17:00# Then ' ...
编辑:日期文字是相对的(那么它们在技术上是文字吗?):
mydate = #Jan 3# ' Jan 3 of the current year
VB。NET,因为它是编译的,所以不支持相对日期文字。只支持日期或时间字面量,但缺失的时间或日期被假定为零。
编辑[2]:当然,有一些奇怪的极端情况会出现相对日期……
mydate = #Feb 29# ' executed on 2010-01-05, yields 2/1/2029
在php中:
easter_date -获取给定年份复活节午夜的Unix时间戳
Int easter_date ([Int $year])
在我看来,在c#中能够将超出范围的整数转换为枚举是非常奇怪的。想象一下这个枚举:
enum Colour
{
Red = 1,
Green = 2,
Blue = 3
}
现在,如果你写:
Colour eco;
eco = (Colour)17;
编译器认为这很好。还有运行时。
请看这里了解更多细节。
在Bash中,变量可以显示为标量和数组:
$ a=3
$ echo $a
3
$ echo ${a[@]} # treat it like an array
3
$ declare -p a # but it's not
declare -- a="3"
$ a[1]=4 # treat it like an array
$ echo $a # acts like it's scalar
3
$ echo ${a[@]} # but it's not
3 4
$ declare -p a
declare -a a='([0]="3" [1]="4")'
$ a=5 # treat it like a scalar
$ echo $a # acts like it's scalar
5
$ echo ${a[@]} # but it's not
5 4
$ declare -p a
declare -a a='([0]="5" [1]="4")'
KSH做同样的事情,但是使用排版而不是声明。
当你在zsh中这样做时,你得到的是子字符串赋值而不是数组:
$ a=3
$ a[2]=4 # zsh is one-indexed by default
$ echo $a
34
$ a[3]=567
$ echo $a
34567
$ a[3]=9
$ echo $a
34967
$ a[3]=123 # here it overwrites the first character, but inserts the others
$ echo $a
3412367
$ a=(1 2 3)
$ echo $a
1 2 3 # it's an array without needing to use ${a[@]} (but it will work)
$ a[2]=99 # what about assignments?
$ echo $a
1 99 3
BrainFuck语言。真的是这样!