开发者

Debugging javascript method parameters

开发者 https://www.devze.com 2023-04-06 16:40 出处:网络
I am trying to simply detect that current method has which parameters so i am calling arguments in chrome developer tools while i pause execution in that method. But arguments returns [] empty array.

I am trying to simply detect that current method has which parameters so i am calling arguments in chrome developer tools while i pause execution in that method. But arguments returns [] empty array. But if i try to put some parameters inside function so this time arguments and parameters get filled. There is no anything wrong about this ?

Example:

function(){
  console.log(arguments);//value is []
}

function(a,b,c){
  console.log(arguments);//value is not not empty array. It contains few parameters.
}

I don't understand how can it be ?

Edit :

Now i check it and it works but let me tell you when it is not working.

I simply use debugger then open console and write arguments and enter. Result is [] but if i using arguments in function and i see that it is filled correctly. So why just referencing arguments in console product [] res开发者_Python百科ult ?


Sorry if this doesn't answer your question... it's a little hard to understand what your actual question is...

If you're trying to find how many arguments a function expects, then you can use .length:

f0 = function () { };
f1 = function (a) { };
f2 = function (a, b) { };

f0.length; // 0
f1.length; // 1
f2.length; // 2

Source: http://es5.github.com/#x15.3.5.1


If you're trying to find how many arguments a function received then you can use arguments.length. Note that it has nothing to do with the number of expected arguments.

f = function () {
    return arguments.length;
};

f();     // 0
f(1);    // 1
f(1, 1); // 2
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号