At the end of this class, you will be able to:
class
keyword syntax.wilson-espina/jsd-9-resources
repo to your computerDocuments/JSD/jsd-9-resources/14-prototypal-inheritance
Open up: 00-objects-codealong
const batman = {
name: 'Bruce Wayne',
alias: 'The Bat-man',
usePower: function () {
return 'Spend money and hit people'
}
}
const spiderman = {
name: 'Peter Parker',
alias: 'Spidey',
usePower: function () {
return 'Hang on walls and shoot webs'
}
}
Type of Exercise
Location
starter-code > 01-make-car-exercise
Timing
8 mins |
|
Open up: 02-constructor-codealong
function Hero(name, alias, power, usePower) {
this.name = name
this.alias = alias
this.power = power
this.usePower = usePower
}
Type of Exercise
Location
starter-code > 03-constructor-exercise
Timing
5 mins |
|
Object
which sits on the top of an inheritance chain.Object
allows all objects to access properties such as toString
and constructor
.__proto__
property, which is the object that is used in the lookup chain to resolve methods, etc.
const newObj = {};
newObj.__proto__
// proto object
prototype
property, which is a reference to another object.prototype
.prototype chain
.prototype
PROPERTY
function Cat(name, breed) {
this.name = name;
this.breed = breed;
}
Cat.prototype.species = "Felis Catus";
Cat.prototype.meow = function() {
return `Meow! I’m ${this.name}`;
}
// Cat.prototype object
{
species: "Felis Catus",
meow: function() {
return `Meow! I’m ${this.name}`;
}
}
prototype
PROPERTYlet felix = new Cat("Felix", "Bengal Cat");
{
// Individual properties created by constructor function
name: "Felix",
breed: "Bengal Cat",
// Inherited from Cat.protoype object
species: "Felis Catus",
meow: function() {
return `Meow! I’m ${this.name}`;
}
Open up: 04-prototypes-codealong
Type of Exercise
Location
starter-code > 06-prototypes-exercise
Timing
8 mins |
|
Open up: 07-prototypal-inheritance-codealong
Type of Exercise
Location
starter-code > 08-prototypes-lab
Timing
10 mins |
|
prototype
property: a reference to another object that is often an instance of the constructor object.__proto__
(or “dunder proto”): a property used by web browsers that indicates an object’s parent in the prototype chain.
function Vehicle(color) {
this.color = color;
}
Constructor
=
class Vehicle {
constructor(color) {
this.color = color;
}
}
Class Keyword (ES6)
function Car(color) {
this.color = color;
}
Car.prototype = new Vehicle();
Constructor + Prototype
=
class Car extends Vehicle() {
constructor(color) {
super(color);
}
}
Class + Extends & Super Keywords (ES6)
Open up: 09-classes-codealong
Type of Exercise
Location
starter-code > 10-classes-lab
Timing
Until 20:45 |
|
class
keyword syntax.this
keyword refers to in different situations.(Lesson #14)