在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
当前回答
在Javascript中,我认为以下是等价的:
a['title'] = "Syntactic sugar is good for yr teeth.";
a.title = "Syntactic sugar is good for yr teeth.";
其他回答
下面的c#代码抛出NullReferenceException而不是打印1:
static void SomeMethod(string format, params object[] args)
{
Console.WriteLine(args.Length);
}
static void Main(string[] args)
{
SomeMethod("blabla", null, "Ok here"); // print 2
SomeMethod("blabla", null); // exception
}
在JavaScript中:
1 / 0; // Infinity
1 / -0; // -Infinity
Java泛型 都是WTF:
List<String> ls = new ArrayList<String>(); //1
List<Object> lo = ls; //2
2:是非法的(??)这是令人费解的,但你必须想想接下来会发生什么:
lo.add(new Object());
String s = ls.get(0);
我们将对象赋值给字符串引用,哦不!就像这样,他们周围有很多陷阱。
反向波兰符号。这意味着实参在函数之前。换句话说,2加2就是2 +。
具有WTF特性的语言包括Forth、Postscript(是的,激光打印机的Postscript)和Factor。
我发现Javascript Date Object对110年的热爱令人愉快。 试一试。
<Script language ="JavaScript">
<!--
var now = new Date()
var dia = now.getDay()
var mes = now.getMonth()
var fecha
//Day of the week
if(dia==0){
fecha="Domingo, ";
}else if(dia==1){
fecha="Lunes, ";
}else if(dia==2){
fecha="Martes, ";
}else if(dia==3){
fecha="Miércoles, ";
}else if(dia==4){
fecha="Jueves, ";
}else if(dia==5){
fecha="Viernes, ";
}else{
fecha="Sábado, ";
}
fecha = fecha + now.getDate() + " de "
//Which month is it?
if(mes==0){
fecha=fecha + "Enero"
}else if(mes==1){
fecha=fecha + "Febrero"
}else if(mes==2){
fecha=fecha + "Marzo"
}else if(mes==3){
fecha=fecha + "Abril"
}else if(mes==4){
fecha=fecha + "Mayo"
}else if(mes==5){
fecha=fecha + "Junio"
}else if(mes==6){
fecha=fecha + "Julio"
}else if(mes==7){
fecha=fecha + "Agosto"
}else if(mes==8){
fecha=fecha + "Septiembre"
}else if(mes==9){
fecha=fecha + "Octubre"
}else if(mes==10){
fecha=fecha + "Noviembre"
}else{
fecha=fecha + "Diciembre"
}
//Year
fecha = fecha + " del " + now.getYear()
document.write(fecha);
//-->
</Script>
脚本是西班牙语-抱歉如果你不明白代码..这个想法是为了让你看到110年的结果。