颤憟吧,凡人! / 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()等价
Object.prototype.inherit = (function inherit(){
var caller = arguments.callee.caller;
caller && ((caller == caller.prototype.constructor) || (this instanceof caller) && caller.prototype.constructor.apply(this, arguments));
});
(function(){
var $kw = 1;
var prw = "protect" + ["", "ed", "ee"][$kw];
function mk(o){
var p = {};
o[prw] = eval("[function " + prw + "(n){\r\nreturn pick(ensure(this, o, p), n);\r\n}][0]");
return p;
}
function pick(p, n){
return p && (n ? p[n] : p);
}
function ensure(ds, o, p){
var caller = arguments.callee.caller;
return caller.caller && (ds instanceof caller.caller) && ((o == ds) ? p : mk(ds));
}
mk(Object.prototype);
})();
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
神棍你好,神棍再见。
