Context - Demonstration

3 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$99.99
List Price:  $139.99
You save:  $40
€96.96
List Price:  €135.76
You save:  €38.79
£80.48
List Price:  £112.68
You save:  £32.19
CA$144.46
List Price:  CA$202.25
You save:  CA$57.79
A$161.30
List Price:  A$225.82
You save:  A$64.52
S$136.99
List Price:  S$191.80
You save:  S$54.80
HK$777.77
List Price:  HK$1,088.91
You save:  HK$311.14
CHF 90.85
List Price:  CHF 127.20
You save:  CHF 36.34
NOK kr1,136.41
List Price:  NOK kr1,591.02
You save:  NOK kr454.61
DKK kr723.41
List Price:  DKK kr1,012.81
You save:  DKK kr289.39
NZ$179.27
List Price:  NZ$250.99
You save:  NZ$71.71
د.إ367.26
List Price:  د.إ514.18
You save:  د.إ146.92
৳12,128.31
List Price:  ৳16,980.12
You save:  ৳4,851.81
₹8,576.54
List Price:  ₹12,007.50
You save:  ₹3,430.96
RM449.95
List Price:  RM629.95
You save:  RM180
₦154,533.88
List Price:  ₦216,353.62
You save:  ₦61,819.73
₨27,801.31
List Price:  ₨38,922.95
You save:  ₨11,121.63
฿3,449.55
List Price:  ฿4,829.51
You save:  ฿1,379.96
₺3,537.66
List Price:  ₺4,952.87
You save:  ₺1,415.20
B$618.15
List Price:  B$865.44
You save:  B$247.28
R1,871.01
List Price:  R2,619.49
You save:  R748.48
Лв189.93
List Price:  Лв265.91
You save:  Лв75.98
₩146,672.33
List Price:  ₩205,347.13
You save:  ₩58,674.80
₪365.15
List Price:  ₪511.23
You save:  ₪146.07
₱5,820.16
List Price:  ₱8,148.46
You save:  ₱2,328.30
¥15,717.92
List Price:  ¥22,005.72
You save:  ¥6,287.80
MX$2,062.93
List Price:  MX$2,888.18
You save:  MX$825.25
QR363.91
List Price:  QR509.49
You save:  QR145.58
P1,387.42
List Price:  P1,942.44
You save:  P555.02
KSh12,902.87
List Price:  KSh18,064.53
You save:  KSh5,161.66
E£5,074.19
List Price:  E£7,104.07
You save:  E£2,029.88
ብር12,747.15
List Price:  ብር17,846.53
You save:  ብር5,099.37
Kz91,190.88
List Price:  Kz127,670.88
You save:  Kz36,480
CLP$100,306.99
List Price:  CLP$140,433.80
You save:  CLP$40,126.81
CN¥731.98
List Price:  CN¥1,024.81
You save:  CN¥292.82
RD$6,097.60
List Price:  RD$8,536.88
You save:  RD$2,439.28
DA13,576.62
List Price:  DA19,007.81
You save:  DA5,431.19
FJ$232.59
List Price:  FJ$325.64
You save:  FJ$93.04
Q770.19
List Price:  Q1,078.30
You save:  Q308.10
GY$20,875.31
List Price:  GY$29,226.27
You save:  GY$8,350.96
ISK kr13,930.45
List Price:  ISK kr19,503.19
You save:  ISK kr5,572.73
DH1,006.87
List Price:  DH1,409.67
You save:  DH402.79
L1,858.26
List Price:  L2,601.64
You save:  L743.38
ден5,964.46
List Price:  ден8,350.49
You save:  ден2,386.02
MOP$799.84
List Price:  MOP$1,119.81
You save:  MOP$319.96
N$1,873.51
List Price:  N$2,622.99
You save:  N$749.48
C$3,673.10
List Price:  C$5,142.49
You save:  C$1,469.38
रु13,705.64
List Price:  रु19,188.44
You save:  रु5,482.80
S/374.69
List Price:  S/524.59
You save:  S/149.89
K399.88
List Price:  K559.85
You save:  K159.96
SAR375.52
List Price:  SAR525.74
You save:  SAR150.22
ZK2,780.17
List Price:  ZK3,892.35
You save:  ZK1,112.18
L482.45
List Price:  L675.45
You save:  L193
Kč2,440.45
List Price:  Kč3,416.73
You save:  Kč976.28
Ft40,319.96
List Price:  Ft56,449.56
You save:  Ft16,129.60
SEK kr1,111.16
List Price:  SEK kr1,555.68
You save:  SEK kr444.51
ARS$103,239.67
List Price:  ARS$144,539.67
You save:  ARS$41,300
Bs689.83
List Price:  Bs965.79
You save:  Bs275.96
COP$436,758.87
List Price:  COP$611,479.89
You save:  COP$174,721.02
₡50,884.43
List Price:  ₡71,240.24
You save:  ₡20,355.80
L2,537.04
List Price:  L3,551.96
You save:  L1,014.92
₲781,454.93
List Price:  ₲1,094,068.17
You save:  ₲312,613.23
$U4,391.87
List Price:  $U6,148.80
You save:  $U1,756.92
zł414.23
List Price:  zł579.94
You save:  zł165.71
Already have an account? Log In

Transcript

In your examples folder, open up the context sub folder. And let's look at the context basic example. Here I have two objects, foo and bar. Each one of these objects has two properties, a greeting property, and a greet property. Now with objects when a property happens to be a function, it's called a method. So each one of these objects has a greet method.

So the Foo dot greet or the greet method of foo, returns this greeting. Now, in a method, this keyword is very important. It refers to the function the object to which a method belongs. So this keyword on line number five refers to foo, because this method greet belongs to this object foo. So once again, the JavaScript this key Word inside of a method refers to the object to which that method belongs. On line number five, describe greeting, resolves to food greeting, on line number 13.

This talk greeting resolves to bardock greeting. So our console log outputs should equal I am foo, and I am bar because we're calling foo dot greet, and bar dot greet. So let's see this in action. If I open up, block scope. Context place for example, I see I am foo and I am bar. And that's exactly what we expect.

Now, there's something we can do that might make this a little bit clearer. Inside of the bar dot greet method. I'm going to put a console during statements I'm going to say console during this. I'm going to just inspect this so we can just get a little bit deeper understanding of what this means online and 13 so now when I rerun the code, I see this object in my console. And I can see it's got two properties greet, which is a function and greeting I am bar. And if I do if I take this and move it inside of foo, foo dot greedy greet.

When I rerun this code, now it's object you can see it's kind of greet method and a greeting. I am foo. So the thing to remember about context is that it is the object to which a method belongs. So inside of a method, the JavaScript this keyword can be used to reference the object to which that method belongs here inside of foo, that this keyword references foo, here inside of bar that this keyword references bar. So this greeting, resolves to bar greeting and this time Greeting on line five resolves to food greeting

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.