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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:38:39+00:00 2026-05-13T05:38:39+00:00

I was just trying to learn and understand jQuery source code (so far with

  • 0

I was just trying to learn and understand jQuery source code (so far with little success X_X) in order to improve my JavaScript skills. As my understand of JavaScript increases I came up with this little logging/debugging tool. As of my level of JavaScript I am posting the code here for people to judge and audit. So potentially I can learn from the comments made. Can someone please point out potential issues, improvements? I tried to encapsulate the console implementation and map it to window.$console (the only place that messes with global scope).

(function() {
    var proxy = {}, //use private proxy object to prevent binding to global (window) object
        _id = "",
        _warning = false;
        results = {};

    if (this.$console) { //check if $console exists in global (window)
        warning("$console is conflicting with existing object and could not be mapped.");
    }
    else {
        this.$console = proxy; //if undefined we then map proxy to global (window) object
    }

    proxy.init = function(id) { //map the display ol html element on the page
        _id = id;
        results = document.getElementById(id);
        return this;
    }

    proxy.log = function(msg) {
        append(msg);
        return this;
    };

    proxy.assert = function(pass, msg) {
        var html = (pass) ? "<b style=\"color: green;\">Pass</b>, " + msg
                    : "<b style=\"color: red;\">Fail</b>, " + msg ;
        append(html);
        return this;
    }

    proxy.error = function(msg) {
        var html = "<b style=\"color: red;\">Error</b>, " + msg + "";
        append(html);
        return this;
    }

    function append(msg) {
        if (results != null) {
            results.appendChild(getChild("li", msg));
        }
        else {
            warning("Message could not be appended to element with \"Id: " + _id + "\".");
        }
        return this;
    };

    function getChild(type, html) {
        var child = document.createElement(type);
        child.innerHTML = html;
        return child;
    }

    function warning(msg) {
        if (!_warning) {
            _warning = true;
            alert(msg);
        }
    }

    return proxy;
}());

Usage

$console.init("console").log("hello world");
$console.assert(true, "This is a pass.");

ps: As I’ve made a few revisions to the code the question is quite different from what it was originally.

  • 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-13T05:38:39+00:00Added an answer on May 13, 2026 at 5:38 am

    It seems like it would work OK. I find your use of anonymous functions a bit confusing, though. Since Console doesn’t have any private data, why not define it like so:

    var Console = {
    
        instance: document.getElementById('console'),
    
        Print: function (msg) {
            this.instance.innerHTML += msg;
            return this;
        },
    
        Log: function (msg) {
            this.Print("<br/>").Print(msg);
        }
    };
    

    I also removed the anonymous function used in the assignment of instance, since it didn’t appear to be doing anything.

    Edit

    The evaluation-of-an-anonymous-function technique is typically used to hide declared variables. See http://yuiblog.com/blog/2007/06/12/module-pattern/ for a discussion.

    If, for example, you wanted to hide the instance property, you might achieve that using an anonymous function in the following way:

    var Console = (function () {
    
        // object containing public members to be returned
        var c = {};
    
        // not visible outside anonymous function
        var instance = document.getElementById('console');
    
        // a 'public' property
        c.Print = function (msg) {
            instance.innerHTML += msg;
            return this;
        };
    
        // a 'public' property
        c.Log = function (msg) {
            this.Print("<br/>").Print(msg);
        };
    
        return c;
    }());
    

    The resulting Console object exposes only the Print and Log properties.

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

Sidebar

Related Questions

I am newbie to jQuery , just trying to learn it since last couple
I was just trying to learn the syntax of the beginner things, and how
I'm trying to learn some C#.net. I'm just trying to expose the AdventureWorks database
This might sound like a stupid question but just trying to learn something here.
Alright, I'm just trying to learn about using Contact information, but I'm a bit
Just a noob trying to learn, I came out with a problem that when
I am just testing and trying to learn how assembler works with C. So
I am trying to learn some DirectX API and, for now, I have just
Trying to create a facebook app just to learn and coming across a strange
I'm looking at modifying a toy OS system and I'm just trying to learn

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.