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

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


当前回答

在php中:

easter_date -获取给定年份复活节午夜的Unix时间戳

Int easter_date ([Int $year])

其他回答

在早期版本的Visual Basic中,没有“Return”语句的函数只是“Return None”,没有任何编译器警告(或错误)。

这导致了最疯狂的调试会话,那时我必须每天处理这种语言。

我喜欢这类东西在JavaScript中很好的事实:

var futureDate = new Date(2010,77,154);
alert(futureDate);

结果是距离2010年第0个月的第0天77个月零154天,即2016年11月1日

在JavaScript中,你可以使用双位负(~~n)来代替Math.floor(n)(如果n是正数)或parseInt(n, 10)(即使n是负数)。N | N和N & N总是得到和~~ N相同的结果。

var n = Math.PI;
n; // 3.141592653589793
Math.floor(n); // 3
parseInt(n, 10); // 3
~~n; // 3
n|n; // 3
n&n; // 3

// ~~n works as a replacement for parseInt() with negative numbers…
~~(-n); // -3
(-n)|(-n); // -3
(-n)&(-n); // -3
parseInt(-n, 10); // -3
// …although it doesn’t replace Math.floor() for negative numbers
Math.floor(-n); // -4

单个位的求反(~)计算-(parseInt(n, 10) + 1),因此两个位的求反将返回-(-(parseInt(n, 10) + 1) + 1)。

更新:这里有一个jsPerf测试用例,比较了这些替代方案的性能。

在ColdFusion中,数组从1开始。

Javascript中有很多东西会让你流泪。

局部变量的作用域,举个简单的例子:

function foo(obj)
{
  for (var n = 0; n < 10; n++)
  {
    var t;        // Here is a 't'
    ...
  }
  t = "okay";     // And here's the same 't'
}