Guest User

Untitled

a guest
Nov 23rd, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. # `this` keyword
  2.  
  3. ## Objectives
  4. - Write an example of a function call
  5. - Write an example of a method call
  6. - Explain what the context (`this`) is on a function call
  7. - Explain what the context (`this`) is on a method call
  8. - Explain what `this` is
  9. - Describe why `this` is important
  10.  
  11. ## What is an example of a function call?
  12.  
  13. On your slates, write a function call for the following function definition
  14.  
  15. ```js
  16. function add(a,b){
  17. return a + b;
  18. }
  19. ```
  20.  
  21. ## What is an example of a method call?
  22.  
  23. On your slates, write a method call for each function in the following object
  24.  
  25. ```js
  26. const Math = {
  27. sum: function(a,b){ return a + b; },
  28. sub: function(a,b){ return a - b; },
  29. mult: function(a,b){ return a * b; },
  30. div: function(a,b){ return a / b; },
  31. }
  32.  
  33. ```
  34.  
  35. ## What is the context (`this`) of a function call?
  36.  
  37. On your slates, write down what the context is on a function call.
  38.  
  39. ## What is the context (`this`) of a method call?
  40.  
  41. On your slates, write down what the context is on a method call.
  42.  
  43. ## In the following example, what is the context of `this` at the method call?
  44.  
  45. ```
  46. const person = {
  47. fname: 'John',
  48. lname: 'McClane',
  49. print: function(){
  50. console.log(`${this.fname} ${this.lname}`
  51. }
  52. }
  53.  
  54. person.print()
  55. ```
  56.  
  57. On your slates, write down what `this` is a reference to.
  58.  
  59. ## What is the `this` keyword?
  60.  
  61. Turn to your neighbor and explain what the `this` keyword is.
  62.  
  63. ## Why is the `this` keyword important?
  64.  
  65. Turn to your neighbor and explain why the `this` keyword is important.
Add Comment
Please, Sign In to add comment