Reputation:
I can get a list of all functions and parameters that belong to a particular js object by doing something like this :-
x = IDBKeyRange.only(43); for ( var each in x ) { console.log(each, x[each]); }
Is there any way I can get more information about the functions, such as the number of arguments each function accepts etc?
Upvotes: 1
Views: 40
Reputation: 1466
you can run debug mode in web browser. and use jquery qualifier to acces to your object.
Upvotes: 0
Reputation: 413712
The length
property of a function gives the number of formal parameters in the declaration, though that's not necessarily the same as the number of parameters the function accepts. That can't really be figured out except by some static/dynamic analysis.
A function's .toString()
method returns the source code. (This isn't in any standard but all environments I know of work that way. And of course you can't get the source of "built-in" functions.) Also trying to make anything but experimental/diagnostic/debugging code work by examining function source code at runtime probably indicates some serious design issues :-)
Upvotes: 3
Reputation: 1074148
I can get a list of all functions and parameters that belong to a particular js object by doing something like this :-
That will give you the enumerable properties of the object, which may well not include a lot of things. For instance, if you do that on an array, you won't see push
because it's a non-enumerable property (of the array's prototype in this case, but it holds for both own properties and inherited ones).
Is there any way I can get more information about the functions, such as the number of arguments each function accepts etc?
You can get the arity of a function (the number of declared arguments) using the length
property of the function instance. For example:
console.log("The arity of [].push is " + [].push.length);
It's important to remember, though, that JavaScript functions may accept a variable number of arguments via the arguments
object, and so arity may not give you the full story.
Upvotes: 2