-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththis.js
More file actions
47 lines (33 loc) · 1.29 KB
/
this.js
File metadata and controls
47 lines (33 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Follow the instructions and fill in the blank sections.
// There are no tests for this file.
// To verify your code works you can run this file using `node this.js` while in the `/src` folder
/* part 1 */
class User {
constructor({ username, password }) {
this.username = username;
this.password = password;
}
}
function checkPassword(str) {
if (this.password === str) return true;
return false;
}
const me = new User({
username: 'LambdaSchool',
password: 'correcthorsebatterystaple',
});
const result = me.checkPassword('correcthorsebatterystaple'); // should return `true` const result = me.checkPassword('correcthorsebatterystaple'); // should return `true`
console.log(result);
const checkPassword = function comparePasswords(passwordToCompare) {
if (this.password === passwordToCompare) return true;
return false;
};
console.log(checkPassword.call(me, 'correcthorsebatterystaple'));
console.log(checkPassword.apply(me, ['correcthorsebatterystaple']));
const testBind = checkPassword.bind(me);
console.log(testBind('correcthorsebatterystaple'));
// invoke `checkPassword` on `me` by explicitly setting the `this` context
// use .call, .apply, and .bind
// .call
// .apply
// .bind