At the end of this class, you will be able to:
thiswilson-espina/jsd-9-resources repo to your computerDocuments/JSD/jsd-9-resources/15-closures-this
function Vehicle(colour) {
this.colour = colour;
}
Constructor
=
class Vehicle {
constructor(colour) {
this.colour = colour;
}
}
Class Keyword (ES6)
function Car(colour) {
this.colour = colour;
}
Car.prototype = new Vehicle();
Constructor + Prototype
=
class Car extends Vehicle() {
constructor(colour) {
super(colour);
}
}
Class + Extends & Super Keywords (ES6)
Open up: 00-classes-codealong
Type of Exercise
Location
starter-code > 01-classes-labTiming
10mins |
|
let or const creates local scope within any block, including blocks that are part of loops and conditionals.
return statement: outer function returns reference to inner function.
Open up: 02-closures-codealong
Open up: 02-closures-codealong
Key Objective
Type of Exercise
Location
starter-code > 03-closures-labTiming
12 mins |
|
Immediatley-Invoked Function Expression
"Iffy"
const countDown = function() {
let counter;
for(counter = 3; counter > 0; counter--) {
console.log(counter);
}
}();
(function countDown() {
let counter;
for(counter = 3; counter > 0; counter--) {
console.log(counter);
}
})();
Open up: 04-iife-codealong
const counter = function () {
let count = 0;
return {
reset: function () {
count = 0;
}
getCount: function () {
return count;
}
increment: function () {
count++
}
}
}();
Open up: 05-modules-codealong
Type of Exercise
Location
starter-code > 06-modules-exerciseTiming
10 mins |
|
thisthis refers to the object that the function is executing in.| SITUATION | WHAT this MAPS TO |
|---|---|
| 1. method invocation | the object that owns the method |
| 2. constructor function | the newly created object |
| 3. event handler | the element that the event was fired from |
| 4. function invocation | the global object ( |
| 5. function invocation (strict mode) |
|
| 6. arrow function | the context of the caller |
Open up: 07-this-codealong
Key Objective
Type of Exercise
Location
starter-code > 08-this-exerciseTiming
6 mins |
|
Key Objective
Type of Exercise
Location
starter-code > 09-closures-labTiming
12 mins |
|
(Lesson #15)