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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:32:16+00:00 2026-05-22T20:32:16+00:00

I would like to create function objects (yes, all functions are objects) with some

  • 0

I would like to create function objects (yes, all functions are objects) with some control over the prototypal inheritance, that is, I would like one function to inherit from another.

I can make objects that have prototypal inheritance, and know to set the prototype property of a function performing as a constructor to initialize the [[prototype]] property of the object.

However, when creating a function, I must use the function operator or the Function constructor. I could try to swizzle Function.prototype, but (1) don’t know if that is writable, and (2) that just seems quite dangerous [still, I should try doing that].

btw: I only care to do this for V8 within node.JS, so if there are means that work only for that environment, that would be acceptable.

For the record, I have seen this:
Is it possible to create a function with another prototype than Function.prototype?

  • 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-22T20:32:16+00:00Added an answer on May 22, 2026 at 8:32 pm

    In V8 (and most other browsers/engines except IE) you can change an object’s prototype by setting the __prototype__ __proto__ attribute. Setting the prototype attribute will instead change the prototype that is used to create an object if the function is invoked as a constructor function. This should not be what you want.

    Afaik there currently is no standard conform way to directly “subclass” a function (or array for that matter). There’s only Object.create, but there is no Function.create or Array.create.

    EDIT: I just realized that function objects do not have the __prototype__ attribute and changing / setting it will not turn an object into a function.
    I believe though that I just recently watched a talk by Brendan Eich (the creator of JavaScript) in which he talked about Function and Array equivalents of Object.create. And infact, googling for “Function.create brendan eich” reveals the following blog post by Eich in which he talks about his wish to implement Function.create and Array.create.

    EDIT 2: Ok, I screwed up. Pretty much. The non-standard attribute is of course __proto__ and not __prototype__. Setting __proto__ works fine for functions with some restrictions, which are:

    1. To be able to call aFunction you must initialize it with an actual function, eg:

      var aFunction = function () {};
      

      This is important. Calling a function does not access the prototype chain, so if you define aFunction as an object and simply set the __proto__ attribute, you will not able to call aFunction.

    2. You can now assign any other function to aFunction.__proto__ and reading any members (including methods) will correctly delegate to the prototype chain if the porperty is not found on aFunction itself.

    3. Calling aFunction() will always invoke the function that was originally declared when aFunction was defined and will never invoke aFunction‘s prototype function. So the body of the function is not subject to inheritence.

    Sorry for screwing up first with the name of the attribute. Hope this helps you nevertheless.

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

Sidebar

Related Questions

I would like create my own collection that has all the attributes of python
I would like create a web service in ASP.Net 2.0 that will supports JSON.
I would like to create a stored procedure in MySQL that took a list
I would like to create events for certain resources that are used across various
I would like to create a UIView has multiple UITextFields validates each one as
I would like to create a base class that will be inherited by other
Would like to create a strong password in C++. Any suggestions? I assume it
I would like to create a database backed interactive AJAX webapp which has a
I would like to create an SSL connection for generic TCP communication. I think
I would like to create a file format for my app like Quake, OO,

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.