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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:07:18+00:00 2026-05-22T22:07:18+00:00

If you open this JSFiddle , you should see in Firebug/Chrome Dev Tools that

  • 0

If you open this JSFiddle, you should see in Firebug/Chrome Dev Tools that an exception is thrown when x.method is called, as method does not exist.

However if you run either Object.method or Function.method in the console you’ll see that they do indeed exist in their respective prototypes.

I’m sure its a simply inheritence issue, but its beyond me at this point as to why the method method isn’t bubbling up to the x Object.

The code is as follows:

// Crockford's Object.create shim
if (typeof Object.create !== 'function') {
    Object.create = function (o) {
        var F = function () {};
        F.prototype = o;
        return new F();
    };
}

// Add a method creation function to the Function prototype
// Note that on this line I've also tried:
// Object.prototype.method = Function.prototype.method = function (name, func) { 
Function.prototype.method = function (name, func) {
    this.prototype[name] = func;
    return this;
};

// Create our object
var x = Object.create({});

// Add common methods to the prototype of our new object
x.method('logNumber', function (num) {
    console.log(num);
});

// Try it out
x.logNumber(6);
  • 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-22T22:07:19+00:00Added an answer on May 22, 2026 at 10:07 pm

    [note] jsfiddle seems to be down at the moment, so I couldn’t check your code

    This function:

    Function.prototype.method = function (name, func) {
        this.prototype[name] = func;
        return this;
    };
    

    adds a method to the Function prototype. An Object is created using a constructor function: a function that, called with the new keyword, will create instances of the Object it constructs. In the Object.create ‘shim’ the constructor function is F, but the shim returns an instance of it (new F()).

    Variable x is not a constructor Function, but an instance. You can only call method from Function.prototype, so x.method is undefined.

    Not using Object.create may show you how it works:

    function X(){}; //=> new X will create an instance of an empty Object
    X.method('logNumber', function (num) {
         console.log(num);
    });             //=> call 'method' from the constructor: now it's working
    var x = new X;  //=> create an instance
    x.logNumber(6); //=> behold!
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Chaps, I got this list that doesn't open the other list. http://jsfiddle.net/mdamC/147/ I want
I have an excel spreadsheet that is password-protected. I need to open this spreadsheet
I found this open-source library that I want to use in my Java application.
Any idea why this accordion isn't working correctly? Only the clicked division should open/close
In this jsfiddle , please follow the steps below: 1: When you open fiddle
Firefox doesn't know how to open this address because the protocol (c) isn't associated
I found this open question online. How do you process a large data file
recently I downloaded this open source project and I am trying to compile it.
I want to download this open source application, and they are using Git. What
What is the most elegant way to solve this: open a file for reading,

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.