JavaScript Tutorial – what is prototype object




Object keeps different properties and some may be methods also.
Every object is associated with another prototype object.

Object inherits all properties from the prototype object.

{} empty object inherits properties from it’s prototype object Object.prototype.
[] empty array inherits properties from it’s prototype object Array.prototype.

Object.getPrototypeOf(o) returns prototype object of object o.

new Object also creates a new empty object that also inherits properties from Object.prototype.

Object() is a constructor function and Object.prototype is the prototype property defined on the Object() constructor function.

Constructor function constructs a new object and this is the reason it is called constructor function.

var a = new Array();
Prototype object of a = Array.prototype

var a = [];
Prototype object of a = Array.prototype

var o = {};
Prototype object of o = Object.prototype

var o = new Object();
Prototype object of o = Object.prototype

var r = new RegExp(‘search’);
Prototype object of r = RegExp.prototype

Facebook page:
https://www.facebook.com/pages/WebTunings/339234242822202

Recommended JavaScript Book:

Code snippets:
https://github.com/webtunings

Original source


44 responses to “JavaScript Tutorial – what is prototype object”

  1. javascript prototypal inheritance is not the same as inheritance in java, it does not have the same concept of inheritance of java or c, your arrow should point to the other direction to the parent prototypal not the child prototypal, it does not inherit the properties of the parent, it's a reference to the parent.  For example, if you have created an object1 that there is a constructor, you created another javascript object2 using the new operator from object1, then when you called object2.prototype.constructor, which you might think you call constructor for object2, however, since object2 has a reference to the same prototype of object1, when you call object2.prototype.constructor, you are calling object1.constructor, and on top of that, object2 has the reference to the top level object.prototype function as well (prototypal chain) .  this guy might have the idea what's going on with prototype, but he misleading by pointing the arrow downward, by doing this, it's kind of like creating a inherit copy of properties like the classic inheritance did with super class.  It's called prototypal inheritance doesn't mean that it's inheritance, I like to call it prototypal, that's it, I can call it orange if I chose to, the point is, they are not the same concept, if you choose to call this inheritance like many people did, at least get the arrow correct.  Your video is misleading think that new or object literal is inheriting the object.prototype, but they are not. your arrows should go opposite direction, while in java land, it's the way you do it. 

  2. Thanks for your response. I am just trying var obj = {}, this should give me undefined right, when i press Enter? but i don't see the result on the fly. Just like you are showing in your training class.

  3. Thanks for uploading such a wonderful explanation. I have been trying to learn JavaScript from couple of month. Could you please suggest me some book or a proper source that covers all the concepts about JavaScript

    I would appreciate if you recommend all the books that you had refereed to learn JavaScript

Leave a Reply