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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:03:09+00:00 2026-05-16T08:03:09+00:00

I have some object, say son , which I’d like to inherit from another

  • 0

I have some object, say son, which I’d like to inherit from another object father.

Of course I can make a constructor function for father, like

Father = function() {
  this.firstProperty = someValue;
  this.secondProperty = someOtherValue;
}

And then use

var son = new Father();
son.thirdProperty = yetAnotherValue;

but this is not exactly what I want. Since son is going to have many properties, it would be more readable to have son declared as an object literal. But then I don’t know how to set its protoype.

Doing something like

var father = {
  firstProperty: someValue;
  secondProperty: someOtherValue;
};
var son = {
  thirdProperty: yetAnotherValue
};
son.constructor.prototype = father;

will not work, as the prototype chain seems to be hidden and not care about the change of constructor.prototype.

I think I can use the __proto__ property in Firefox, like

var father = {
  firstProperty: someValue;
  secondProperty: someOtherValue;
};
var son = {
  thirdProperty: yetAnotherValue
  __proto__: father
};
son.constructor.prototype = father;

but, as far as I understand, this is not a standard feature of the language and it is better not to use it directly.

Is there a way to specify the prototype for an object literal?

  • 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-16T08:03:10+00:00Added an answer on May 16, 2026 at 8:03 am

    You’re right, __proto__ is a non-standard property, and the only two standard ways you have to set a new object’s [[Prototype]], are:

    • Through the use of a constructor and the new operator (as you already mention).
    • Using the ECMAScript 5 Object.create method.

    Object.create is not widely supported yet (works on IE9Pre3+, Firefox 3.7Alpha+, Chrome 5+ Safari 5+, Rhino 1.7), but at some point all the implementations will conform the ES5 spec.

    It can take two arguments, the first one is the object that will be used as the [[Prototype]] of the new object, and the second one, is another object where the own properties can be described (in the same structure that you would use Object.defineProperties).

    For example:

    var father = {
      firstProperty: 1,
      secondProperty: 2
    };
    
    var son = Object.create(father, {
      thirdProperty: {
        value: 'foo'
      }
    });
    
    father.isPrototypeOf(son); // true
    son.firstProperty; // 1
    

    The son internal [[Prototype]] property will refer to father, and it will contain a value property named thirdProperty.

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

Sidebar

Related Questions

I have some problems during when and which object to be release You can
I have some JS code which generates the following object, return { type: some
So I have an object which has some fields, doesn't really matter what. I
I have an object which straight forward instance variables. Some are NSString, some are
Assume you have some objects which have several fields they can be compared by:
Say you have some boiler plate using statements. Say something like this: #if !NUNIT
Say I have some simple class and once it's instantiated as an object I
Say that i have some classes like this example. class A { int k,
Let's say I have the following ruby code : def use_object(object) puts object.some_method end
Lets say I have a Dictionary object: Dictionary myDictionary<int, SomeObject> = new Dictionary<string, SomeObject>();

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.