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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:26:02+00:00 2026-05-26T05:26:02+00:00

This is more of an exploratory question, seeing how the core JavaScript stuff works.

  • 0

This is more of an exploratory question, seeing how the core JavaScript stuff works. I realize the convention is to not override any core JavaScript classes, but I just can’t seem to wrap my head around this one.

You can create what acts like “class methods” in JavaScript by adding to the core Function prototype like this:

Function.prototype.class_method = function() {
  console.log("class method called")
}

var User;
User = (function() {
  function User() {}
  return User;
})();

User.class_method(); // "class method called"

My question is, is there a way to add “instance methods” in a similar way? Something crazy like this, but what’s below doesn’t work (or make any sense):

alias = Function.prototype.constructor;
Function.prototype.constructor = function() {
  child = this;
  child.prototype.instance_method = function() {
    console.log("instance method called");
  }
  alias.apply(child);
}

var user = new User();
user.instance_method(); // method doesn't exist

It’s almost like you’d need to override the Function class’ constructor method and access the prototype from there. Is this possible?

It does work if you add to the Object.prototype like this:

Object.prototype.instance_method = function() {
  console.log("instance method");
}

var user = new User();
user.instance_method(); // "instance method called"

But that doesn’t seem right either, mainly because seeing the output in the node.js console from console.log({}); change is confusing:

console.log({});
// {};

Object.prototype.instance_method = function() {
  console.log("instance method");
}

console.log({});
// {"instance_method": [Function]}
  • 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-26T05:26:02+00:00Added an answer on May 26, 2026 at 5:26 am

    If you are using node.js, you should be able to use Object.defineProperty [MDN] and make the new property non-enumerable:

    Object.defineProperty(Object.prototype, 'instance_Method', {
        value: function() {
            console.log("instance method");
        },
        enumerable: false // it's already the default
    });
    

    This was introduced in ECMAScript5, so only newer browsers will support it.

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

Sidebar

Related Questions

This is more of an academic inquiry than a practical question. Are there any
Ok, I'm going to try to make this more clear because my last question
This is more of an generic XML Schema question, but if and how do
This is more an observation than a real question: MS-Access (and VBA in general)
This is more of a syntax question I'm trying to write a store procedure
This is more of a business-oriented programming question that I can't seem to figure
this is more theoretical question. I have written simple chat with my friend. We
This more a question about the why then 'how-to', yet it has been annoying
Is there a module which can do this more nicely (not only replacing the
This more of a style question, rather than a how to. So I've got

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.