At the end of this class, you will be able to:
this
wilson-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-lab
Timing
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-lab
Timing
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-exercise
Timing
10 mins |
|
this
this
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-exercise
Timing
6 mins |
|
Key Objective
Type of Exercise
Location
starter-code > 09-closures-lab
Timing
12 mins |
|
(Lesson #15)