Skip to content

Commit 97b1ae7

Browse files
committed
set up and answer questions on THIS
1 parent 33d1564 commit 97b1ae7

2 files changed

Lines changed: 25 additions & 18 deletions

File tree

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ This challenge focuses on using the `this` keyword as well as getting comfortabl
66

77
**Follow these steps to set up and work on your project:**
88

9-
* [ ] Create a forked copy of this project.
10-
* [ ] Add your project manager as collaborator on Github.
11-
* [ ] Clone your OWN version of the repository (Not Lambda's by mistake!).
12-
* [ ] Create a new branch: git checkout -b `<firstName-lastName>`.
13-
* [ ] Implement the project on your newly created `<firstName-lastName>` branch, committing changes regularly.
14-
* [ ] Push commits: git push origin `<firstName-lastName>`.
9+
* [x] Create a forked copy of this project.
10+
* [x] Add your project manager as collaborator on Github.
11+
* [x] Clone your OWN version of the repository (Not Lambda's by mistake!).
12+
* [x] Create a new branch: git checkout -b `<firstName-lastName>`.
13+
* [x] Implement the project on your newly created `<firstName-lastName>` branch, committing changes regularly.
14+
* [x] Push commits: git push origin `<firstName-lastName>`.
1515

1616
**Follow these steps for completing your project.**
1717

assignments/this.js

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,33 @@
11
/* The for principles of "this";
2-
* in your own words. explain the four principle for the "this" keyword below.
3-
*
4-
* 1.
5-
* 2.
6-
* 3.
7-
* 4.
8-
*
9-
* write out a code example of each explanation above
10-
*/
2+
* in your own words. explain the four principle for the "this" keyword below.
3+
*
4+
* 1. Global: THIS is the Javascript object built into the WINDOW/CONSOLE
5+
* 2. Implicit: the object to the left of the DOT is what THIS is talking about like CONSOLE in console.log
6+
* 3. NEW: when we have a Function that makes a object- the NEW object is what THIS is referreing to
7+
* 4. Explicit: using CALL or APPLY forces you to spell out what THIS is in the implicit format
8+
*
9+
* write out a code example of each explanation above
10+
*/
1111

1212
// Principle 1
13-
1413
// code example for Window Binding
14+
console.log(this);
15+
// THIS is accessing the CONSOLE because we didn't tell it a context.
1516

1617
// Principle 2
17-
1818
// code example for Implicit Binding
19+
console.log(this);
20+
// THIS is accessing the CONSOLE because console is the object to the left of the DOT.
1921

2022
// Principle 3
2123

2224
// code example for New Binding
23-
25+
function book(title, author, subject) {
26+
this.title = title;
27+
this.author = author;
28+
this.subject = subject;
29+
console.log('${this.title} by ${this.author}');
30+
}
2431
// Principle 4
2532

2633
// code example for Explicit Binding

0 commit comments

Comments
 (0)