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

  • Home
  • SEARCH
  • 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 7623823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:48:11+00:00 2026-05-31T04:48:11+00:00

I am newbie about javascript.So I do not know what is the name of

  • 0

I am newbie about javascript.So I do not know what is the name of I looking for and How do I do it?

After you read question if you thing question title is wrong, you should change title.

I am using console.log for debugging but this is causing error if browser IE. I made below function for this problem.

var mylog=function(){
   if (devmode && window.console){
      console.log(arguments);
   }
};

mylog("debugging");

Now I want to use all console functions without error and I can do that as below.

var myconsole={
   log:function(){
        if (devmode && window.console){
          console.log(arguments);
       }
   }
   ,error:function(){
        if (devmode && window.console){
          console.error(arguments);
       }
   }

  ...
  ...
  ...


};

But I do not want to add all console functions to myconsole object severally.
I can do that in PHP with below code.

class MyConsole
{
  function __call($func,$args)
  {
     if ($devmode && function_exists('Console')){
        Console::$func($args); // Suppose that there is Console class.
     }   
  }
}

MyConsole::warn("name",$name);
MyConsole::error("lastname",$lastname);

This is possible with __noSuchMethod__ method but this is specific to only firefox.

Thanks for helping.

  • 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-31T04:48:12+00:00Added an answer on May 31, 2026 at 4:48 am

    Unfortunately, you can’t do that in JavaScript, the language doesn’t have support for the “no such method” concept.

    Two options for you:

    Option 1:

    Use strings for your method name, e.g.:

    function myconsole(method) {
        var args;
    
        if (devmode && window.console) {
            args = Array.prototype.slice.apply(arguments, 1);
            window.console[method].apply(window.console, args);
        }
    }
    

    Usage:

    myconsole("log", "message");
    myconsole("error", "errormessage");
    

    The meat of myconsole is here:

    args = Array.prototype.slice.apply(arguments, 1);
    window.console[method].apply(window.console, args);
    

    The first line copies all of the arguments supplied to myconsole except the first one (which is the name of the method we want to use). The second line retrieves the function object for the property named by the string in method from the console object and then calls it via the JavaScript apply function, giving it those arguments.

    Option 2:

    A second alternative came to me which is best expressed directly in code:

    var myconsole = (function() {
    
        var methods = "log debug info warn error assert clear dir dirxml trace group groupCollapsed groupEnd time timeEnd profile profileEnd count exception table".split(' '),
            index,
            myconsole = {},
            realconsole = window.console;
    
        for (index = 0; index < methods.length; ++index) {
            proxy(methods[index]);
        }
    
        function proxy(method) {
            if (!devmode || !realconsole || typeof realconsole[method] !== 'function') {
                myconsole[method] = noop;
            }
            else {
                myconsole[method] = function() {
                    return realconsole[method].apply(realconsole, arguments);
                };
            }
        }
    
        function noop() {
        }
    
        return myconsole;
    })();
    

    Then you just call log, warn, etc., on myconsole as normal.

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

Sidebar

Related Questions

Newbie question about PostgreSQL. I'm migrating a MySQL/PHP app I've created, hosted on a
I'm learning Java, and I know one of the big complaints about newbie programmers
As a relative newbie I try to read as much as I can about
Before anything, I should admit that I am completely a newbie about Java Swing.
I have a newbie question about the following: - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
Sorry about this newbie question. Is there a way to execute multiple sentences at
I'm starting with developing, sorry about this newbie question. I need to create a
I am web-designer, not a programmer and a newbie in Javascript / jQuery (although
I know this probably must be a newbie question, but since I don't know
(This is really a newbie question about Rake & Rails & dependencies in general.

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.