Why prototypes manually initialized to null still inherit from Object — Javascript?

Briefly, if a constructor's prototype isn't an Object, then instances are given Object. Prototype as their prototype The detail is in ECMA-262, §13.2.2 Construct: When the Construct internal method for a Function object F is called with a possibly empty list of arguments, the following steps are taken: Let obj be a newly created native ECMAScript object Set all the internal methods of obj as specified in 8.12 Set the Class internal property of obj to Object Set the Extensible internal property of obj to true Let proto be the value of calling the Get internal property of F with argument prototype If Type( proto ) is Object, set the Prototype internal property of obj to proto If Type( proto ) is not Object, set the Prototype internal property of obj to the standard built-in Object prototype object as described in 15.2.4 Let result be the result of calling the Call internal property of F providing obj as the this value and providing the argument list passed into Construct as args If Type( result ) is Object then return result Return obj Noting that in items 6 and 7 null is Type null (ECMA-262 §8.2), it is not the same as typeof null which is object.

Briefly, if a constructor's prototype isn't an Object, then instances are given Object. Prototype as their prototype. The detail is in ECMA-262, §13.2.2 Construct: When the Construct internal method for a Function object F is called with a possibly empty list of arguments, the following steps are taken: Let obj be a newly created native ECMAScript object.

Set all the internal methods of obj as specified in 8.12. Set the Class internal property of obj to "Object". Set the Extensible internal property of obj to true. Let proto be the value of calling the Get internal property of F with argument "prototype".

If Type(proto) is Object, set the Prototype internal property of obj to proto. If Type(proto) is not Object, set the Prototype internal property of obj to the standard built-in Object prototype object as described in 15.2.4. Let result be the result of calling the Call internal property of F, providing obj as the this value and providing the argument list passed into Construct as args.

If Type(result) is Object then return result. Return obj. Noting that in items 6 and 7, null is Type null (ECMA-262 §8.2), it is not the same as typeof null, which is object.

1 for digging out the ECMA spec. – alex Jun 10 at 1:13.

When you instantiate it like that, it returns an object of o. Its (hidden) prototype chain still points to Object.

– rubixibuc Jun 10 at 0:48 @rubixibuc A Function is always an Object in JavaScript. There is no primitive type for it. – alex Jun 10 at 0:54 rubixibuc - if you set a constructor's prototype to anything that isn't Type(Object), then instances constructed by it will have Object.

Prototype as their prototype. – RobG Jun 10 at 1:07 @RobG Which is weird, because I've found browsers erroneously say typeof null == 'object'. – alex Jun 10 at 1:13.

Briefly, if a constructor's prototype isn't an Object, then instances are given Object. Prototype as their prototype. Let obj be a newly created native ECMAScript object.

Set the Class internal property of obj to "Object". Set the Extensible internal property of obj to true. With argument "prototype".

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions