Skip to content

Commit 277b72e

Browse files
DylanDylan
authored andcommitted
made improvements to this
1 parent aff0b73 commit 277b72e

1 file changed

Lines changed: 9 additions & 14 deletions

File tree

src/this.js

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,36 @@
44

55
class User {
66
constructor(options) {
7+
// set a username and password property on the user object that is created
78
this.username = options.username;
89
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;
1610
}
1711
// create a method on the User class called `checkPassword`
1812
// this method should take in a string and compare it to the object's password property
1913
// return `true` if they match, otherwise return `false`
14+
checkPassword(str) { if (str === this.password) return true;
15+
return false;
16+
};
2017
}
2118

2219
const me = new User({ username: 'LambdaSchool', password: 'correcthorsebatterystaple' });
2320
const result = me.checkPassword('correcthorsebatterystaple'); // should return `true`
2421

2522
const checkPassword = function comparePasswords(passwordToCompare) {
26-
if (passwordToCompare === this.password) {
27-
return true;
28-
}
29-
return false;
3023
// recreate the `checkPassword` method that you made on the `User` class
3124
// use `this` to access the object's `password` property.
3225
// do not modify this function's parameters
3326
// note that we use the `function` keyword and not `=>`
27+
if (passwordToCompare === this.password) return true;
28+
return false;
3429
};
3530

3631
// invoke `checkPassword` on `me` by explicitly setting the `this` context
3732
// use .call, .apply, and .bind
38-
checkPassword.call(me, 'correcthorsebatterystaple');
33+
checkPassword.call(me, this.password);
3934
// .call
40-
checkPassword.apply(me, ['correcthorsebatterystaple']);
35+
checkPassword.apply(me, [this.password]);
4136
// .apply
4237
const checkMyPassword = checkPassword.bind(me);
43-
checkMyPassword('correcthorsebatterystaple');
38+
checkMyPassword(this.password);
4439
// .bind

0 commit comments

Comments
 (0)