颤憟吧,凡人! / Shock, Motals!
//IE, FF, Opera, GC
function(){
alert("hello!");
}();
//x,x,o,x
function(){
alert("hello!");
}.call();
//x,x,o,x
(function(){
alert("hello!");
}());
//o,o,o,o
var a = function(){
alert("hello!");
}();
//o,o,o,o
//语法问题
alert(eval("{}"));
//x,x,x,x
alert(eval("({})"));
//o,o,o,o
//语法问题
alert(eval("function(){}"));
//x,x,o,o
alert(eval("(function(){})"));
//x,o,o,o
alert(eval("[function(){}][0]"));
//o,o,o,o
//应该是BUG
("l".a)();
//o,o,o,o
"l"["a"]();
//o,o,o,o
//和"l".a()等价
function xhrCallback(xhr, resolver){
return (function(){
var state = xhr.readyState;
var status = xhr.status;
resolver[state] ? (resolver[state][status] ? resolver[state][status].call(xhr) : (resolver[state].$ && resolver[state].$.call(xhr)), resolver[state]._ && resolver[state]._.call(xhr)) : (resolver.$ && resolver.$.call(xhr));
resolver._ && resolver._.call(xhr);
});
}
var xhr = new XHR;
xhr.open("GET", "http://yoursite/", true);
xhr.onreadystatechange = xhrCallback(xhr, { 4 : { 200 : (function(){
alert("Hello, Web!");
}), $ : (function(){
alert("Oops!");
}), _ : (function(){
document.write("Mission accomplished");
}) } });
xhr.send(null);
Author:优雅的神棍 / Elegant Tales
神棍你好,神棍再见。
