0

I am using the following code snippet from the documentation of a tool (FullScale Dangle):

$scope.displayCoord = function(type, term) {
    console.log(term);
    console.log(type);
};

This function is called on-click after being routed through the tool's own library. According to the documentation, I have the parameters type, and term available to the function after the onclick.

How can I determine what additional parameters are available?

3
  • 1
    By far the easiest way to know what they are and how to use them would be to look them up in the documentation.
    – Alex Wayne
    Commented Apr 8, 2014 at 17:37
  • The documentation for this was woefully incomplete. I ended up sorting through the mini-fied code and learning where the developer calls the callback function.
    – JSK NS
    Commented Apr 8, 2014 at 17:40
  • Yeah, that kind of sucks. Sometimes it's necessary though. You can do as Niet suggests below, but figuring why that argument is there and how you use it still won't be obvious. You may still have to trace through the code of a poorly documented library to figure it out.
    – Alex Wayne
    Commented Apr 8, 2014 at 17:50

3 Answers 3

4

Use the arguments array-like object. This means you can do arguments.length to see how many there are, and access them as arguments[0] (type), arguments[1] (term), and any others that may be there.

1

Using the arguments object, something like this should do it:

var f = function (args1, args2) {console.log(arguments);}("foo", "bar", "bing");

["foo", "bar", "bing"]

1

As mentioned in the other answers, you can use the arguments object. Here's more information available on it's use. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions_and_function_scope/arguments

Not the answer you're looking for? Browse other questions tagged or ask your own question.