📄 7-4.txt
字号:
function checkargs() { // arguments.caller.callee is the Function object that called us. // Its arity property is the number of arguments that were expected. var expected = arguments.caller.callee.arity; // arguments.caller is the arguments object of the function that // called us. Its length property is the number of actual args passed. var passed = arguments.caller.length; // If they don't match, do some fancy regular expression work to get // the name of the calling function, and display a warning. if (passed != expected) { var funcname = arguments.caller.callee.toString().match(/function (\w*)/)[1]; alert("WARNING:\n" + funcname + "() " + "was invoked with wrong number of arguments!\n" + "Expected " + expected + " arguments, but passed " + passed); }}// Here is a test function that uses checkargs().function f(x,y,z) { checkargs(); return x+y+z; }f(1,2,3); // Passed the right number of argumentsf(1,2); // Passed too few arguments; checkargs() displays a warning.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -