What is the difference between __proto__
and prototype
I read most of articles in the web and I still cannot understand it..
as far as I understand
__proto__
is the property which is for prototype object
prototype
is the actual object
am I correct? ....
Why only functions have prototype property? And how is it be an object?
var fn = function(){};
console.dir(fn);
output
function fn() arguments: null caller: null length: 0 name: "" prototype: Object __proto__: () <function scope>
Using object and function I try to set values for __proto__
and prototype in chrome console as shown below
//create object and display it
var o = {name : 'ss'};
console.dir(o);
output
Object name: "ss", __proto__: Object
//set the values
o.__proto__ = 'aaa';
o.prototype = 'bbb';
//after set the values display the object
console.dir(o);
output
Object name: "ss", prototype: "aaa", __proto__: Object
//create function and display it
var fn = function(){};
console.dir(fn);
output
function fn() arguments: null caller: null length: 0 name: "" prototype: Object __proto__: () <function scope>
//set the values
fn.prototype = 'fff';
fn.__proto__ = 'eee';
//after set the values display the object
console.dir(fn);
output
function fn() arguments: null caller: null length: 0 name: "" prototype: "fff" __proto__: function() <function scope>
Then I realize that I can't set values for __proto__
but can set values to prototype
. W why can't I set values for __proto__
???