Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # `this` keyword
- ## Objectives
- - Write an example of a function call
- - Write an example of a method call
- - Explain what the context (`this`) is on a function call
- - Explain what the context (`this`) is on a method call
- - Explain what `this` is
- - Describe why `this` is important
- ## What is an example of a function call?
- On your slates, write a function call for the following function definition
- ```js
- function add(a,b){
- return a + b;
- }
- ```
- ## What is an example of a method call?
- On your slates, write a method call for each function in the following object
- ```js
- const Math = {
- sum: function(a,b){ return a + b; },
- sub: function(a,b){ return a - b; },
- mult: function(a,b){ return a * b; },
- div: function(a,b){ return a / b; },
- }
- ```
- ## What is the context (`this`) of a function call?
- On your slates, write down what the context is on a function call.
- ## What is the context (`this`) of a method call?
- On your slates, write down what the context is on a method call.
- ## In the following example, what is the context of `this` at the method call?
- ```
- const person = {
- fname: 'John',
- lname: 'McClane',
- print: function(){
- console.log(`${this.fname} ${this.lname}`
- }
- }
- person.print()
- ```
- On your slates, write down what `this` is a reference to.
- ## What is the `this` keyword?
- Turn to your neighbor and explain what the `this` keyword is.
- ## Why is the `this` keyword important?
- Turn to your neighbor and explain why the `this` keyword is important.
Add Comment
Please, Sign In to add comment