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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:38:51+00:00 2026-06-05T11:38:51+00:00

Suppose I have an object X defined as var X = function () {};

  • 0

Suppose I have an object X defined as

var X = function () {};
X.prototype.doSomething = function () {};
X.prototype.doSomethingElse = function () {};

Is it possible to construct a function f so that f instanceof X?
Note that I must also be able to do f() without a TypeError.


In Mozilla, I can do exactly what I want with __proto__:

var f = function () {};
f.__proto__ = new X;

However, that is (1) nonstandard and (2) deprecated. MDN’s page for __proto__ suggests using Object.getPrototypeOf instead, but what I’m really looking for is an Object.setPrototypeOf (which doesn’t exist, though the idea is brought up in this bug report).

A cheap approximation to what I want is

var f = function () {};
jQuery.extend(f, new X);

Unfortunately, this does not make f instanceof X true (nor would I
expect it to!).

  • 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-06-05T11:38:52+00:00Added an answer on June 5, 2026 at 11:38 am

    No, it is not possible (in a standard way). Every possibility to create a callable object (i.e., a function) will create one inheriting from Function.prototype1; and you can’t change the [[prototype]] of an object afterwards2.

    See also:

    • create function in javascript with custom prototype
    • Can you create functions with custom prototypes in JavaScript?
    • Is it possible to create a function with another prototype than Function.prototype?
    • Can a JavaScript object have a prototype chain, but also be a function?
    • Custom prototype chain for a function
    • Correct prototype chain for Function (for some internals)

    1: OK, ES6 allows us to subclass Function. But that’s not as useful as it sounds.
    2: Since ES6, you can use Object.setPrototypeOf.

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

Sidebar

Related Questions

Suppose I have a method that must return an object (say from a database
Suppose I have a simple function defined that does nothing: function fn() { }
Suppose I have an entity object defined as public partial class Article { public
Suppose I have a user defined type: CREATE OR REPLACE TYPE TEST_TYPE AS OBJECT
Suppose I have an object file ( source.o ) without function main . a
In C#, suppose you have an object (say, myObject ) that is an instance
Suppose I have a customer object that has all of the standard customer properties
Suppose we have following code defined in tester.py class Tester( object ): def method(
Suppose I have an object which is defined as an array of vector points,
Suppose that I have the following python base class: class BaseClass(object): def a(): This

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.