Is instantiating a object really just inheritance in some way in javascript?

No. You are confused because one of the methods of accomplishing inheritance (viz. Prototypal inheritance) takes, as the prototype, a given object.

And one method of acquiring objects is via constructors.

No. You are confused because one of the methods of accomplishing inheritance (viz. Prototypal inheritance) takes, as the prototype, a given object.

And one method of acquiring objects is via constructors. In other words, there is nothing special about someObject. Prototype = new SomeOtherObject().

You could just as well do someObject. Prototype = { myObjectLiteral: "isJustAsGoodAsYourConstructoredInstance" }; or even someObject. Prototype = false.

The two operations, very literally, have nothing to do with each other. EDIT To address the quote OP found in his book: "Recall the relationship between constructors, prototypes, and instances: each constructor has a prototype object that points back to the constructor, and instances have an internal pointer to the prototype. " Unfortunately, this is misleading at best, and plain wrong at worst.

Consider what "each constructor has a prototype object that points back to the constructor" would mean. It would mean that, for example, Array. Prototype === Array Function.

Prototype === Function function CustomConstructor() { } CustomConstructor. Prototype === CustomConstructor But all of these statements output false if you type them in your console. Now consider "instances have an internal pointer to the prototype."

This is true, but does not fit with the terminology he is using. What this means is: var myProto = {}; function CustomConstructor() { } CustomConstructor. Prototype = myProto; // inherit from the myProto object.

Var x = new CustomConstructor(); // x is an "instance" Object. GetPrototypeOf(x) === myProto; // Object. GetPrototypeOf fetches the "internal pointer" But as you can see, I didn't inherit using a constructor, as I tried to point out above.

Instantiating an object is not inheritance in any way. It is simply that the prototype property of constructors is how prototypal inheritance is accomplished, just like classical inheritance is accomplished by placing extends BaseClass after a class definition in Java. In turn, this difference is present because prototypal inheritance lets you inherit a prototype object instance, not a base class.

The JavaScript Garden has a few good sections that might help if you want more information. Relevant are "The Prototype," "Constructors," and "The instanceof Operator.

" And I explained why they do not, with clear counterexamples. The fact that they look similar to you is just an artifact of the particular examples you used. – Domenic Jun 18 at 4:26 JavaScript for web developers, By:Nicholas Zakas - "Recall the relationship between constructors, prototypes, and instances: each constructor has a prototype object that points back to the constructor, and instances have an internal pointer to the prototype.

" – James Fair Jun 18 at 4:42 @James updated to dissect that unfortunate quote. – Domenic Jun 18 at 4:57 Thanks, I understand now. Instances are not objects but only "point" to objects(the funny thing is I have always known that.

LOL). Also, the prototype does point back to the constructor, but not in the way you described it. It is actually like this someObject.prototype.constructor.

If you have a skype, add me (lonewolf456123) so we can discuss futher. – James Fair Jun 18 at 6:06.

Without using objectType.inherits() if I got your concept of inheritance then it is if you take just the right part: new someOtherObject() This is instantiation of someOtherObject. What happens here is you are creating an object of type someOtherObject that inherits structure from an empty object (provided you have not set a prototype on this). Because the default value of prototype is an empty object {}.

You are putting this object as prototype of someObject: someObject. Prototype = new someOtherObject(); Now if you create an instance of someObject this will happen: You create someObject that inherits the structure of someOtherObject in that point in time, which inherits the structure of (empty)object when it has been instanced. Maybe a better explanation is saying that the instance gets extended with the structure of its prototype at that point in time, and leave all of the inheriting wording aside, since just using that can mislead.

Since classic inheritance uses base classes (types) and proto uses instances of those. Now it all depends on how you look at inheritance, which to argue about does not exists at all in javascript (object types are mutable at runtime) as by Karl Marx argues that real communism is not possible at all in the concept. If you agree with this last statement then comparing and asking about it does not matter, because neithercase is.

Thanks very helpful – James Fair Jun 18 at 4:25 This is a bit misleading, because it talks as if someOtherObject were an actual type. That is not how prototypal inheritance works. Instead, someObject (an instance, not a type) inherits a set of properties/methods from the particular instance new someOtherObject().

If you had done var x = new someOtherObject(); x. Foo = "bar"; someObject. Prototype = x; then someObject would have inherited the foo property, even though it wasn't related to someOtherObject.So... be careful saying things like "someObject that inherits someOtherObject which inherits (empty)object." – Domenic Jun 18 at 4:29 To be constructive, a better formulation would be "someObject inherits the properties/methods that new someOtherObject() happens to have at this point in time.

" – Domenic Jun 18 at 4:32 Thanks for the wording. I have reflected that in the sentence, since it was a bit misleading. – Marino Å imić Jun 18 at 4:41 1 Maybe a better explanation is saying that the instance gets extended with the structure of its prototype at that point in time, and leave all of the inheriting wording aside, since just using that can mislead.

– Marino Å imić Jun 18 at 4:44.

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