7-4.txt

来自「Javascript语言开发经典教程开发」· 文本 代码 · 共 23 行

TXT
23
字号
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 + =
减小字号Ctrl + -
显示快捷键?