i wrote the code to figure out the relationship between __proto__ of an instance and the prototype of its constructor in javascript for me:
// Constructor
var Guy = function( name ) {
this.name = name;
};
// Prototype
var chinese = {
region: "china",
myNameIs: function() {
return this.name;
}
};
Guy.prototype = chinese;
var he = new Guy( "Wang" );
var me = new Guy( "Do" );
i was given a false as i tested whether me.__proto__ is equal to chinese:
console.log( "__proto__ of me is chinese? " + chinese == me.__proto__ ); // logs false
Why were they not the same thing?
Because
+has higher precedence than==, so you’re really doing…what you need to do is…
or use a
,in theconsolecall to pass separate arguments…