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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:12:50+00:00 2026-06-16T09:12:50+00:00

This question isn’t a duplicate of Using "Object.create" instead of "new" . The thread

  • 0

This question isn’t a duplicate of Using "Object.create" instead of "new". The thread in question doesn’t focus on passing arguments correctly when using Object.create


I am curious as to how I would go about initializing objects using Object.create as opposed to new. Here is my code so far:

function Human(eyes) {
    this.eyes = eyes || false;
}

Human.prototype.hasEyes = function() {
    return this.eyes;
}

function Male(name) {
    this.name = name || "No name";
}

Male.prototype = new Human(true); //passing true to the Human constructor

var Sethen = new Male("Sethen");

console.log(Sethen.hasEyes());

As you can see above, the Male.prototype = new Human(true); creates a new object with true. When the hasEyes() function is run, this logs true as expected.

So, my question is.. using Object.create how would I go about doing this the same way passing a true parameter??

  • 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-16T09:12:52+00:00Added an answer on June 16, 2026 at 9:12 am

    You must call the constructor using Object.call(this) and then pass your arguments.

    function Human(eyes, phrase) {
        this.eyes = eyes || false;
        this.phrase = phrase;
    }
    
    Human.prototype.hasEyes = function() {
        return this.eyes;
    }
    
    Human.prototype.sayPhrase = function() {
        return this.phrase;
    }
    
    function Male(name) {
        Human.call(this, true, "Something to say"); //notice the call and the arguments
        this.name = name || "No name";
    }
    
    Male.prototype = Object.create(Human.prototype);
    
    var Sethen = new Male("Sethen");
    
    console.log(Sethen.hasEyes());
    console.log(Sethen.sayPhrase());
    
    console.log(Object.getOwnPropertyNames(Sethen));
    

    This works and now the object Male has the properties of eyes and phrase

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

Sidebar

Related Questions

I am using CodeCharge Studio to finish a large PHP application. This question isn't
Sorry, still reasonably new to Javascript here, so hope this question isn't too embarrassingly
I'm new to Windows Phone 7 App Programming, so I hope this question isn't
This question isn't really a programming question, so it doesn't exactly belong on Stack
I'm new to programming, and hope this question isn't too basic. I've searched the
Hey I'm aware this question isn't very technical, but I'm new to the Delphi
I'm relatively new to web application programming so I hope this question isn't too
Alright, so this question isn't exactly about thread management... well, sort of. I am
I'm quite new to Ruby so I hope this question isn't already answered elsewhere.
What this question isn't asking is how to add a new line below or

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.