|
4 | 4 |
|
5 | 5 | class User { |
6 | 6 | constructor(options) { |
| 7 | + // set a username and password property on the user object that is created |
7 | 8 | this.username = options.username; |
8 | 9 | this.password = options.password; |
9 | | - // set a username and password property on the user object that is created |
10 | | - } |
11 | | - checkPassword(str) { |
12 | | - if (str === this.password) { |
13 | | - return true; |
14 | | - } |
15 | | - return false; |
16 | 10 | } |
17 | 11 | // create a method on the User class called `checkPassword` |
18 | 12 | // this method should take in a string and compare it to the object's password property |
19 | 13 | // return `true` if they match, otherwise return `false` |
| 14 | + checkPassword(str) { if (str === this.password) return true; |
| 15 | + return false; |
| 16 | + }; |
20 | 17 | } |
21 | 18 |
|
22 | 19 | const me = new User({ username: 'LambdaSchool', password: 'correcthorsebatterystaple' }); |
23 | 20 | const result = me.checkPassword('correcthorsebatterystaple'); // should return `true` |
24 | 21 |
|
25 | 22 | const checkPassword = function comparePasswords(passwordToCompare) { |
26 | | - if (passwordToCompare === this.password) { |
27 | | - return true; |
28 | | - } |
29 | | - return false; |
30 | 23 | // recreate the `checkPassword` method that you made on the `User` class |
31 | 24 | // use `this` to access the object's `password` property. |
32 | 25 | // do not modify this function's parameters |
33 | 26 | // note that we use the `function` keyword and not `=>` |
| 27 | + if (passwordToCompare === this.password) return true; |
| 28 | + return false; |
34 | 29 | }; |
35 | 30 |
|
36 | 31 | // invoke `checkPassword` on `me` by explicitly setting the `this` context |
37 | 32 | // use .call, .apply, and .bind |
38 | | -checkPassword.call(me, 'correcthorsebatterystaple'); |
| 33 | +checkPassword.call(me, this.password); |
39 | 34 | // .call |
40 | | -checkPassword.apply(me, ['correcthorsebatterystaple']); |
| 35 | +checkPassword.apply(me, [this.password]); |
41 | 36 | // .apply |
42 | 37 | const checkMyPassword = checkPassword.bind(me); |
43 | | -checkMyPassword('correcthorsebatterystaple'); |
| 38 | +checkMyPassword(this.password); |
44 | 39 | // .bind |
0 commit comments