// caller demo {function callerDemo() { if (callerDemo.caller) { var a= callerDemo.caller.toString(); alert(a); } else { alert("this is a top function"); }}function handleCaller() { callerDemo();} function calleeDemo() { alert(arguments.callee);}function calleeLengthDemo(arg1, arg2) { if (arguments.length==arguments.callee.length) { window.alert("验证形参和实参长度正确!"); return; } else { alert("实参长度:" +arguments.length); alert("形参长度: " +arguments.callee.length); }} // simple call demofunction simpleCallDemo(arg) { window.alert(arg);}function handleSPC(arg) { simpleCallDemo.call(this, arg);}// simple apply demofunction simpleApplyDemo(arg) { window.alert(arg);}function handleSPA(arg) { simpleApplyDemo.apply(this, arguments);} // inheritfunction base() { this.member = "never-online"; this.method = function() { window.alert(this.member); }}function extend() { base.call(this); window.alert(member); window.alert(this.method);} // advanced apply demofunction adApplyDemo(x) { return ("this is never-online, BlueDestiny '" + x + "' demo");}function handleAdApplyDemo(obj, fname, before) { var oldFunc = obj[fname]; obj[fname] = function() { return oldFunc.apply(this, before(arguments)); };}function hellowordFunc(args) { args[0] = "hello " + args[0]; return args;}function applyBefore() { alert(adApplyDemo("world"));}function applyAfter() { handleAdApplyDemo(this, "adApplyDemo", hellowordFunc); alert(adApplyDemo("world")); // Hello world!} 来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/92289/viewspace-988434/ ,如需转载,请注明出处,否则将追究法律责任。