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 7044723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:26:37+00:00 2026-05-28T02:26:37+00:00

So i am lazy and like to give console.info a new function name :)

  • 0

So i am lazy and like to give console.info a new function name 🙂 But i also like to be safe and make sure that i can leave my logging in and not error in browsers that don’t support console.
So i wrote this:

if (typeof console == "object" && typeof console.error == "function") {
    e = console.info; 
}

Now the problem only occurs in chrome and get the following error:

Uncaught TypeError: Illegal invocation

To me this seems like a very general error.

  • 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-28T02:26:37+00:00Added an answer on May 28, 2026 at 2:26 am

    The most likely explanation is that the console object’s info function expects that this within the function will be the console object. That won’t be the case if you do this:

    var e = console.info;
    e("Foo");
    

    Remember that in JavaScript, this is defined entirely by how a function is called, not where it’s defined. More: Mythical methods and You must remember this.

    You’d have to do this instead:

    e.call(console, "Foo");
    

    …which obviously isn’t shorter.

    So to do this reliably, you have to create a function instead:

    function e(msg) {
        console.info(msg);
    }
    

    jAndy pointed out we can also use Function#bind (part of ES5) for this, since Chrome has that and, on Chrome, console.info is a real JavaScript function. So:

    e = console.info.bind(console);
    

    That will only work on browsers that support ES5 (so, not IE8 and earlier for instance) and where console.info is a real JavaScript function (some host-provided functions on some browsers are not, although I think console.info is on most if not all). But if you’re targeting Chrome, you’re golden. Also, bind is one of the ES5 features that’s trivial to implement in a non-ES5 browser (the es5-shim.js project and several others do). But implementing bind purely for this one use is probably overkill, just use the function e(msg) { .. } above. 🙂

    Live example of all of the above

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

Sidebar

Related Questions

I'd like to know how debugging is achieved in a lazy functional language. Can
All what Hibernate reverse engineering generates is something like this @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name
Like a good programmer I guess I'm trying to be lazy and make the
I'd like to use .NET 's Lazy<T> class to implement thread safe caching. Suppose
Can we say making a class Lazy is like making it Singleton ? In
Is there a lazy way I can quickly replace all instances of a word
I'm lazy! And I just want to store one single string value. That's all!
How can I get a lazy array in Ruby? In Haskell, I can talk
I have a long, lazy sequence that I want to reduce and test lazily.
Let's say for example that I have a regular expression like this: The quick

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.