DEV Community

Discussion on: Understanding Classes (ES5) and Prototypal Inheritance in JavaScript

Collapse
 
xgqfrms profile image
xgqfrms • Edited

function Person(name, age) {
    this.name = name;
    this.age = age;
}
// undefined

Person.__proto__;
// ƒ () { [native code] }
Person.prototype;
// {constructor: ƒ}constructor: ƒ Person(name, age)arguments: nullcaller: nulllength: 2name: "Person"prototype: {constructor: ƒ}[[FunctionLocation]]: VM92:1[[Prototype]]: ƒ ()[[Scopes]]: Scopes[2][[Prototype]]: Object

const me = new Person('Eric', 18);
// undefined
me.__proto__;
// {constructor: ƒ}constructor: ƒ Person(name, age)arguments: nullcaller: nulllength: 2name: "Person"prototype: constructor: ƒ Person(name, age)arguments: nullcaller: nulllength: 2name: "Person"prototype: constructor: ƒ Person(name, age)[[Prototype]]: Object[[FunctionLocation]]: VM92:1[[Prototype]]: ƒ ()[[Scopes]]: Scopes[2][[Prototype]]: Object[[FunctionLocation]]: VM92:1[[Prototype]]: ƒ ()[[Scopes]]: Scopes[2][[Prototype]]: Object
me.prototype;
// undefined

me.__proto__ === Person.prototype;
// true

Enter fullscreen mode Exit fullscreen mode