heorling
heorling

Reputation: 379

trying to log the sent arguments in javascript

function log(tobelogged){
    if (debugging){
        c.log(arguments);
        c.log(arguments.toString());
        c.log(tobelogged);
    };
};

and then

log(someObject);

and I want to response

'someObject'
'whatever is in someObject'

I tried toString() above but clearly I'm missing something. How do you get the 'name' of what's sent to the function? The example uses oni apollo stratified sjs in the browser but I don't think it matters here. Anyy ideas?

Upvotes: 1

Views: 823

Answers (2)

user1106925
user1106925

Reputation:

An argument doesn't have a name. It only has a reference via a parameter, or via an index of the arguments object. The parameter name is an indirect reference from the parameter to an index in the arguments object.

In strict mode, there's even less of a correlation, since you can modify the values of the parameters without affecting the value of the arguments object, and vice versa.

I think the closest you'll come is using...

console.dir( arguments ); // instead of console.log 

...which should give you an expandable object, so you can see the arguments by index.

enter image description here

Upvotes: 4

alex
alex

Reputation: 490233

That information is lost and not available in arguments.

You could set a break point there (throw in debugger;) and examine the call stack.

Upvotes: 1

Related Questions