This figure again shows that every object has a prototype. Constructor function Foo also has its own
__proto__
which is Function.prototype, a
!!!THIS IS THE BEST EXPLANATION IN THE WORLD!!!!!
var q = {}
var prototype = {prop: 11}
q.prop // undefined
q.__proto__ = prototype
q.prop // 11
in function constructors javascript engine call this q.__proto__ = prototype
automatically when we write new Class
, and in to the __proto__
prop set Class.prototype
function Class(){}
Class.prototype = {prop: 999} // set prototype as we need, before call new
var q = new Class() // q.__proto__ = Class.prototype
q.prop // 999
Enjoy %)