在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?

请每个回答只回答一个特征。


当前回答

C# has a feature called "extension methods", which are roughly analogous to Ruby mix-ins - Essentially, you can add a method to any pre-existing class definition (for instance, you oould add "reverse()" to String if you were so inclined). That alone is fine- The "Weird" part is that you can add these extension methods, with a method body and everything, to an interface. On the one hand, this can be handy as a way to add a single method to a whole swath of classes which aren't part of the same inheritance tree. On the other, you're adding fleshed out methods to interfaces, essentially breaking the very definition of an interface.

其他回答

PHP (?)

第一:(未设置)类型转换。

$a = 1;
$b = (unset)$a;
var_dump($a); // 1
var_dump($b); // NULL

用法:http://www.php.net/manual/en/language.types.type-juggling.php # 89637

第二:= NULL和unset()函数之间的区别。

$c = 10;
$d = &$c;
$c = NULL;
var_dump($c); // NULL
var_dump($d); // NULL


$e = 10;
$f = &$e;
unset($e);
var_dump($e); // NULL
var_dump($f); // 10 - WTF?

javascript:

parseInt('06'); // 6
parseInt('08'); // 0

Tcl中的连接是将两个字符串添加为一个字符串:

set s1 "prime"
set s2 "number"
set s3 $s1$s2
puts s3

输出为

primenumber

在Python中:

i = 1
++i
print i

输出“1”。行'++i'的计算结果为+(+i) (Python不支持增量操作符)

在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