JavaScript匿名函数 - 如何确定可用参数?

时间:2021-12-19 22:28:55

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

我正在使用工具文档中的以下代码片段(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.

在通过工具自己的库进行路由后,可以单击此函数。根据文档,我有onclick后的参数类型和函数可用的术语。

How can I determine what additional parameters are available?

如何确定可用的其他参数?

3 个解决方案

#1


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.

使用arguments数组对象。这意味着你可以使用arguments.length来查看它们的数量,并将它们作为参数[0](类型),参数[1](术语)以及可能存在的任何其他参数进行访问。

#2


1  

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

使用arguments对象,这样的事情应该这样做:

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

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

[“foo”,“bar”,“bing”]

#3


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

如其他答案中所述,您可以使用arguments对象。以下是有关它的更多信息。 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions_and_function_scope/arguments

#1


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.

使用arguments数组对象。这意味着你可以使用arguments.length来查看它们的数量,并将它们作为参数[0](类型),参数[1](术语)以及可能存在的任何其他参数进行访问。

#2


1  

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

使用arguments对象,这样的事情应该这样做:

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

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

[“foo”,“bar”,“bing”]

#3


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

如其他答案中所述,您可以使用arguments对象。以下是有关它的更多信息。 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions_and_function_scope/arguments