JS - Object prototype assignment

PHOTO EMBED

Thu May 05 2022 18:55:30 GMT+0000 (Coordinated Universal Time)

Saved by @shigure92 #javascript

function Student() {
}

Student.prototype.sayName = function() {
  console.log(this.name)
}

function EighthGrader(name) {
  this.name = name
  this.grade = 8
}

EighthGrader.prototype = Object.create(Student.prototype)

const carl = new EighthGrader("carl")
carl.sayName() // console.logs "carl"
carl.grade // 8
content_copyCOPY

https://www.theodinproject.com/lessons/node-path-javascript-objects-and-object-constructors