0

I need to pass an array as built-in function. For example this works fine:

console.info('%cBlue text%c Red text', 'color:blue', 'color:red');

There are 3 parameters, but what should I do when I got n parameter?

var x = [ '%cBlue text%c Red text...%c nth-Text', 'color:blue', 'color:red', ... , 'nth-color:black']; 
console.info.apply(null, x);

does not work. Thanks in advance.

1 Answer 1

2

It fails because you pass null as context instead of the console object. This works :

console.info.apply(console, x);

More generally, you can use apply for your own functions too, but when they need a context, you must set it.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you dystroy, i got the idea.

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.