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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:19:52+00:00 2026-05-14T15:19:52+00:00

There are only 3 lines of code, and yet I’m having trouble fully grasping

  • 0

There are only 3 lines of code, and yet I’m having trouble fully grasping this:

Object.create = function (o) {
    function F() {}
    F.prototype = o;
    return new F();
};
newObject = Object.create(oldObject);

(from Prototypal Inheritance)

  1. Object.create() starts out by creating an empty function called F. I’m thinking that a function is a kind of object. Where is this F object being stored? Globally I guess.

  2. Next our oldObject, passed in as o, becomes the prototype of function F. Function (i.e., object) F now “inherits” from our oldObject, in the sense that name resolution will route through it. Good, but I’m curious what the default prototype is for an object, Object? Is that also true for a function-object?

  3. Finally, F is instantiated and returned, becoming our newObject. Is the new operation strictly necessary here? Doesn’t F already provide what we need, or is there a critical difference between function-objects and non-function-objects? Clearly it won’t be possible to have a constructor function using this technique.

What happens the next time Object.create() is called? Is global function F overwritten? Surely it is not reused, because that would alter previously configured objects. And what happens if multiple threads call Object.create(), is there any sort of synchronization to prevent race conditions on F?

  • 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-14T15:19:53+00:00Added an answer on May 14, 2026 at 3:19 pm

    1) Object.create() starts out by
    creating an empty function called F.
    I’m thinking that a function is a kind
    of object. Where is this F object
    being stored? Globally I guess.

    No, it’s stored on the local scope of the Object.create function, each time you invoke Object.create this function F will be recreated.

    You could even create a more memory-efficient implementation, by storing F on a closure, and reuse it:

    if (typeof Object.create !== "function") {
      Object.create = (function () {
        function F() {} // created only once
        return function (o) {
          F.prototype = o; // reused on each invocation
          return new F();
        };
      })();
    }
    

    2) Next our oldObject, passed in as o,
    becomes the prototype of function F.
    Function (i.e., object) F now
    “inherits” from our oldObject, in the
    sense that name resolution will route
    through it. Good, but I’m curious what
    the default prototype is for an
    object, Object? Is that also true for
    a function-object?

    All objects have an internal property that builds the prototype chain, this property is known as [[Prototype]], it’s an internal property, although some implementations let you access to it, like mozilla, with the obj.__proto__ property.

    The default [[Prototype]] when you create a new object, i.e. var obj = {}; is Object.prototype.

    All functions have a prototype property, this property is used when a function is used as a Constructor, invoked with the new operator.

    A new object instance it’s created behind the scenes, and this object [[Prototype]] is set to its Constructor’s prototype property.

    3) Finally, F is instantiated and
    returned, becoming our newObject. Is
    the “new” operation strictly necessary
    here? Doesn’t F already provide what
    we need, or is there a critical
    difference between function-objects
    and non-function-objects? Clearly it
    won’t be possible to have a
    constructor function using this
    technique.

    Yes, the new operator is essential in this method.

    The new operator is the only standard way to set the [[Prototype]] internal property of an object, if you are curious about how it works, you can give a look to the [[Construct]] internal operation.

    What happens the next time
    Object.create() is called? Is global
    function F overwritten? Surely it is
    not reused, because that would alter
    previously configured objects. And
    what happens if multiple threads call
    Object.create(), is there any sort of
    synchronization to prevent race
    conditions on F?

    The next time Object.create is invoked, a new local F function is instantiated only within the scope of the method call, you shouldn’t worry about race conditions.

    Note that this implementation hardly conforms the Object.create described in the ECMAScript 5th Edition Specification, in that method, you could pass a property descriptor to initialize the object.

    All browser vendors are implementing it (already available on Firefox 3.7 alphas, latest Wekit Nightly Builds and Chrome 5 Beta), so I would recommend you at least to check if a native implementation exist before overriding it.

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

Sidebar

Related Questions

I have some jQuery/JavaScript code that I want to run only when there is
I just got this quite large CakePHP app (about 20k lines of code), which
I'm trying to click on a link using jquery. There only appears to be
When there were only evil datasets and the microsoft application blocks your transfer objects
I assumed there were only bug fixes/(no new types) in .NET 2.0 SP1 until
Should FIFO queue be synchronized if there is only one reader and one writer?
I had made some questions regarding PHP-GTK (there are only 4 php-gtk tagged questions
What is the best way to hide Tab headers when there is only a
I've installed an instance of SQL 2005 Express on <computername>/SQLEXPRESS . There is only
How much of a performance benefit is there by selecting only required field in

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.