Playing with JS prototype

by María Fernández

JavaScript

class Person {
	constructor(name) {
  	this.name = name;
  }
  
  greeting() {
  	console.log(`Hello, I am ${name};`);
  }
}

const person1 = new Person('Loki');
console.log('instance has name?: ', person1.hasOwnProperty('name'));
console.log('instance has greeting?: ', person1.hasOwnProperty('greeting'));

console.log('instance prototype __proto__ has greeting?: ', person1.__proto__.hasOwnProperty('greeting'));

console.log('instance getPrototypeOf has greeting?: ', Object.getPrototypeOf(person1).hasOwnProperty('greeting'));