0

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 [] result ?

7
  • How do you call these functions? As you posted them, you don't call them and also leave no reference to them. Commented Sep 20, 2011 at 12:53
  • Are we missing some code here? Where is arguments defined? Commented Sep 20, 2011 at 12:53
  • 1
    @ElRonnoco - arguments is part of ecmascript. Commented Sep 20, 2011 at 12:54
  • a fiddle to share. jsfiddle.net/hrhzV Commented Sep 20, 2011 at 12:54
  • @El Ronnoco - arguments is an object available inside every function: developer.mozilla.org/en/JavaScript/Reference/… Commented Sep 20, 2011 at 12:54

1 Answer 1

4

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.