__proto__ vs prototype

by bhupendra negi

JavaScript

// 1 manual creation of objects
const userFunctions = {
increment : function() {this.score++},
display:function() { alert(this.score)}
}

const userCreator = function(name,score) {

const obj = Object.create(userFunctions);
//console.log(obj);
obj.name = name;
obj.score = score;
return obj;

}

const obj1 = userCreator('ram',30);
console.log(obj1);
obj1.increment();
obj1.display();

//2 auto creatiion of objects
const UserCreator = function(name,score) {
this.name = name;
this.score = score;
}
UserCreator.prototype.incerement = function() {this.score++}
UserCreator.prototype.display = function() { alert(this.score)}

const user1 = new UserCreator("Rahul",43);
console.log(user1.__proto__ === UserCreator.prototype);