Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7606659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:27:55+00:00 2026-05-31T00:27:55+00:00

Like all programmers, I’m lazy. So in my utils.js there’s a simple line: window.log

  • 0

Like all programmers, I’m lazy. So in my utils.js there’s a simple line:

window.log = console.log

This works fine in firefox, but it makes Chrome cry like a little boy. I have to write console.log to make it work.

Any suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T00:27:56+00:00Added an answer on May 31, 2026 at 12:27 am

    Chrome’s console.log apparently pays attention to what this is so if you do this:

    window.log = console.log
    log('pancakes')
    

    Then you’ll get nothing more than a “TypeError: Illegal invocation” exception for your efforts. However, if you force the appropriate context thusly:

    log.apply(console, 'pancakes')
    

    then you’ll get your pancakes in the console. That’s why you need to wrap console.log in a function if you want to be lazy and just say log: some console.log implementations need to be called with the appropriate context.

    However, just window.log = (x) -> console.log(x) is not quite correct as console.log is a variadic function. A better implementation would be this:

    window.log = -> console.log.apply(console, arguments)
    

    or to be pedantic, since arguments isn’t an array and Function#apply expects an array, “cast” arguments to a real array in the usual way:

    window.log = -> console.log.apply(console, Array::slice.call(arguments))
    

    That should work the same everywhere and preserve the variadic nature of console.log. I doubt you need to be that pedantic though, just sending arguments in and pretending it is an array should be fine. You could also use CoffeeScript splats as a short form of the [].slice and arguments stuff:

    window.log = (args...) -> console.log(args...)
    

    If you look at the JavaScript version of that you’ll see that it is the slice and arguments stuff in disguise.

    Of course if you’re using plain JavaScript, then one of these will work:

    window.log = function() { console.log.apply(console, arguments) };
    window.log = function() { console.log.apply(console, Array.prototype.slice.call(arguments)) };
    

    Another option is to use Function#bind to force log to be called in the context of console:

    window.log = console.log.bind(console)
    

    The downside is that not every browser supports bind.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi everyone, This is very simple for perl programmers but not beginners like me,
Do programmers like to create deadlines? Im a web developer, and schedules/deadlines are all
I'd like all my content to flow around an image. To do this, I
Even experienced programmers write C# code like this sometimes: double x = 2.5; double
Just curious, I'm wondering what all you experienced programmers or newbies (like me) out
Hi I have a new question for all fellow programmers to solve. Is there
I want to create a live, checkers-like app, which will work like this: There
Like all good programmers, I'm trying to get some things straight when using TDD
This has to be a common question that all programmers have from time to
Hi all fellow programmer I'd like to have a separate js file for each

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.