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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T12:41:20+00:00 2026-05-29T12:41:20+00:00

Object.create is a great addition to JavaScript, because it adheres more to the prototypical

  • 0

Object.create is a great addition to JavaScript, because it adheres more to the prototypical nature of JS. However, I can’t help but find the syntax of the 2nd parameter to the function to be too verbose, and a step back.

For example, if I want to create an object, and specify a new property in the derived object, I need to include that property value within a property object, regardless if I’m interested in the extra features or not.

So, something as simple as this:

 o = Object.create({}, { p: 42 })

Now becomes:

 o = Object.create({}, { p: { value: 42 } }) 

Obviously this is a simple example, but to me the verbosity is unnecessary, and should be optional.

Does anyone understand the decision to require a properties object? What is your opinion of the requirement of the new syntax?

Note: I understand there are easy solutions to overcome this requirement.

  • 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-29T12:41:22+00:00Added an answer on May 29, 2026 at 12:41 pm

    The syntax is done this way so that you can add parameters that control each property:

    So, when you do this:

    o = Object.create({}, { p: { value: 42 } }) 
    

    you are saying that you want a property named p with a value of 42. The key here is that there are other parameters you can set for each property and if there wasn’t this extra level of object hierarchy, you wouldn’t have any way to pass those extra parameters.

    So, for example, you could also do this:

    o2 = Object.create({}, { p: { value: 42, writable: true, enumerable: true, configurable: true } }); 
    

    Here’s you are not just specifying the value of 42, but also some options for that property. If there wasn’t the extra level of object hierarchy here, then you wouldn’t have a place to put those extra options.

    Yes, it does seem inconvenient when you only want the simple case. But, you could easily write yourself a helper function that made the simpler syntax work:

    function myCreate(proto, props, enumerable, writable, configurable) {
        // last three arguments are optional - default them to true if not present
        if (typeof enumerable === "undefined") {enumerable = true;}
        if (typeof writable === "undefined") {writable = true;}
        if (typeof configurable === "undefined") {configurable = true;}
        var wrapper = {};
        for (var i in props) {
            wrapper[i] = {
                value: props[i], 
                enumerable: enumerable, 
                configurable: configurable,
                writable: writable
            };
        }
        return(Object.create(proto, wrapper));
    }
    

    Demo here: http://jsfiddle.net/jfriend00/vVjRA/

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

Sidebar

Related Questions

I can create a Json object as here How to create json by javascript
Can I create relationships between my object stores in IndexedDB? For example, I have
Can you help me out here? A really simple problem but I just can't
How can I create an Object in ruby that will be evaluated to false
If an object has a property that is a collection, should the object create
I want to create object on the client side of aspx page. And i
I want to dynamically create object of HtmlDivElement in my jsf managed bean and
I am confused as to when to create object instances or Static Helper classes.
Say I create an object thus: var myObject = {ircEvent: PRIVMSG, method: newURI, regex:
If I create an object inside of the main scope: INDEX.PHP: $db = new

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.