The Difference Between __proto__ And prototype

JavaScript proto chain
There are several answers here how to check if a property exists in an object.

I was always using

if(myObj.hasOwnProperty(‘propName’))
but I wonder if there is any difference from
if(‘propName’ in myObj){

An example

1
2
3
4
5
6
7
8
var test = function() {}

test.prototype.newProp = function() {}

var instance = new test();

instance.hasOwnProperty('newProp'); // false
'newProp' in instance // true

another example

1
2
3
4
5
6
7
var o  = {"name":"sun nan","university":"Deakin","course":"Bachelor of Information Technology (Programming)-Deakin","email":"417757848@qq.com","first_name":"Nan","last_name":"Sun","date_of_birth":"1993-09-13"}

o.prototype.print = function(){
for(var x in y){
console.log(x, y[x]);
}
}

undefined error will be raise

next example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//In world of JavaScript, very function can be used as a constructor function.
//Let's make a Goddess Object
function Goddess () {
this.name = "Alice";
}

var hand = {
whichOne: "right hand",
someFunction: function(){
console.log("not safe for work.");
}
};

Goddess.prototype = hand;

//then, we can use Goddess as a constructor, construct an Object
var myObject = new Goddess();
console.log(myObject.__proto__ === Goddess.prototype) //true