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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:47:52+00:00 2026-06-15T23:47:52+00:00

Possible Duplicate: How do I make a callable JS object with an arbitrary prototype?

  • 0

Possible Duplicate:
How do I make a callable JS object with an arbitrary prototype?

Let’s say we have multiple individual functions that we can call individually in their own context; But they also inherit some other object’s prototype. Like this:

//Here is the parent object:
var Human = function(){
    this.isAlive = true;
};
Human.prototype.say = function(what){
    alert(what + '!');
};

//These will inherit from it:
var ninja = function() {
    alert("I'm a ninja!");
}
var samurai = function(){
    alert("I'm a samurai!");
}

//Now, how can I make ninja and samurai behave like this:
ninja(); //I'm a ninja!
samurai(); //I'm a samurai!
ninja.say('Hello'); //Hello!

//And they should keep their inheritance. Like:
Human.prototype.die = function(){
    this.isAlive = false;
}

ninja.die();
ninja.isAlive == false;

samurai.isAlive == true;

In other words, is there a way to have two objects that inherit another object’s prototype, but are still callable as functions?

Note: I’m gonna use this in Adobe ExtendScript (aka Crippled Javascript), and it doesn’t know much modern javascript. Like, Object.defineProperty doesn’t work in it. So, is there a normal, standard way to do this?

  • 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-15T23:47:52+00:00Added an answer on June 15, 2026 at 11:47 pm

    Using apsillers’s linked question, I was able to get it working with one adjustment: Human‘s properties and methods are defined as an object:

    Try it out: http://jsfiddle.net/lbstr/JZP2S/

    The key is the HumanMaker function. At a basic level, it takes a function and adds the Human prototype to it. This allows you to invoke your function, get all of the properties from Human and eat it too. Here it is:

    function HumanMaker(f) {
        var h = Human;
        h.__proto__ = f.__proto__;
        f.__proto__ = h;
        return f;
    }
    

    You would invoke it like this:

    var ninja = HumanMaker(function() {
        alert("I'm a ninja!");
    });
    

    Here is the whole thing:

    var Human = {
        isAlive: true,
        say: function(what){
            alert(what + '!');
        },
        die: function(){
            this.isAlive = false;
        }
    };
    
    function HumanMaker(f) {
        var h = Human;
        h.__proto__ = f.__proto__;
        f.__proto__ = h;
        return f;
    }
    
    //These will inherit from it:
    var ninja = HumanMaker(function() {
        alert("I'm a ninja!");
    });
    var samurai = HumanMaker(function(){
        alert("I'm a samurai!");
    });
    
    //Now, how can I make ninja and samurai behave like this:
    ninja(); //I'm a ninja!
    samurai(); //I'm a samurai!
    ninja.say('Hello'); //Hello!
    
    
    ninja.die();
    ninja.isAlive == false;
    
    samurai.isAlive == true;​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Can a JavaScript object have a prototype chain, but also be a
Possible Duplicate: Can I make GCC warn on passing too-wide types to functions? Is
Possible Duplicate: Make uitextfield password obscured I have a app that takes in a
Possible Duplicate: How can JavaScript make new page that contains more JavaScript? I tried
Possible Duplicate: PHP make if shorter I have an if statement that looks like
Possible Duplicate: how to make “pretty rounding” in R? I have a number, say
Possible Duplicate: How can I make a horizontal ListView in Android? I have used
Possible Duplicate: How to make return key on iphone make keyboard disappear? I have
Possible Duplicate: How can I make an EXE file from a Python program? i
Possible Duplicate: ASP.Net:Best way to run scheduled tasks I have to make a scheduled

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.