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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:57:02+00:00 2026-05-29T23:57:02+00:00

Am I mistaking what .prototype is supposed to do, or is this just not

  • 0

Am I mistaking what .prototype is supposed to do, or is this just not working??

window.dump = function () {
    for (var i = 0, x = dump.list.length; i < x; ++i) console.log.apply(this, dump.list[i]);
    if (arguments.length && typeof arguments[0] === 'boolean' && arguments[0]) dump.purge();
}
dump.prototype = {
    list : [],
    log : function () {
        dump.list.push(arguments);
    },
    purge : function () {
        dump.list = [];
    }
}
dump.log('test1');
dump.log('test2');
dump();

I expect “test1” and “test2” to be passed through console.log, instead dump.log is not defined. However dump.prototype.log is.

edit: I’ve tried the following, and I just can’t seem to get this prototype thing right.

window.dump = new function () {
    this.list = [];
    this.log = function () {
        this.list.push(arguments);
    }
    this.purge = function () {
        return this.list = [];
    }
    return function () {
        for (var i = 0, x = this.list.length; i < x; ++i) console.log.apply(this, this.list[i]);
        if (arguments.length && typeof arguments[0] === 'boolean' && arguments[0]) this.purge();
    }
}

I guess what I’m asking is, what is the correct way to be able to use my code as follows?

dump.log('test1');
dump.log('test2');
dump();

edit: Here’s a final result thanks to Matthew Flaschen, for anyone who’s interested in building from it.

(function () {
    var console_log = Function.prototype.bind.call(console.log, console);
    window.dump = function () {
        for (var i = 0, x = dump.list.length; i < x; ++i) console_log.apply(this, dump.list[i]);
        if (arguments.length && typeof arguments[0] === 'boolean' && arguments[0]) dump.purge();
    };
    dump.list = [];
    dump.log = function () {
        dump.list.push(arguments);
    }
    dump.purge = function () {
        dump.list = [];
    }
})();

I’ve had to assign console_log to wrap console.log, because apparently console is not a standard object. Therefore it is not a standard Function object with the apply method. Proof that I do actually use Google.

  • 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-29T23:57:04+00:00Added an answer on May 29, 2026 at 11:57 pm

    Yes, a correct version would be the below. dumper is a constructor function. Thus, it initializes the list member.

    Below, we set the dumper prototype with the desired methods. These can also use this. Any instance of dumper (such as d) will have these methods.

    window.dumper = function () {
        this.list = [];
    };
    
    dumper.prototype = {
    
        log : function () {
            this.list.push(arguments);
        },
        purge : function () {
            this.list = [];
        },
        dump : function () {
            for (var i = 0, x = this.list.length; i < x; ++i) console.log.apply(this, this.list[i]);
            if (arguments.length && typeof arguments[0] === 'boolean' && arguments[0]) this.purge();
        }
    }
    
    
    var d = new dumper();        
    
    d.log('test1');
    d.log('test2');
    d.dump();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Unless I'm mistaken, creating a function in Python works like this: def my_func(param1, param2):
In VS2008 (and earlier if I'm not mistaking) I have dropdown that lets me
I tried with this code in C# but could not get the desired output
Yes, I am having issues with this very basic (or so it seems) thing.
I am working with delphi. I have an array of points which are continues
I'm trying out jquery as a javascript library over prototype. Now when it comes
Possible Duplicate: JavaScript: Class.method vs. Class.prototype.method I am trying to understand object in JavaScript.
I don't even know if this question belongs here or to another StackExchange site,
how can i rewrite www.mysite.com/someURLhere into www.mysite.com/ping.php?url=someURLhere without mistaking local files, and directories as
Take the following code as a sample: procedure TForm1.Button1Click(Sender: TObject); var Obj: TSomeObject; begin

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.