FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaScript-II/src/this.js at master · FJF616/JavaScript-II · GitHub
FJF616
/
JavaScript-II
Public
forked from
bloominstituteoftechnology/JavaScript-II-Stretch-Assignment
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaScript-II
/
src
/
this.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
49 lines (42 loc) · 1.63 KB
Breadcrumbs
JavaScript-II
/
src
/
this.js
Copy path
File metadata and controls
49 lines (42 loc) · 1.63 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
48
49
// 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
(
options
)
{
// set a username and password property on the user object that is created
this
.
username
=
options
.
username
;
this
.
password
=
options
.
password
;
}
// create a method on the User class called `checkPassword`
// this method should take in a string and compare it to the object's password property
checkPassword
(
password
)
{
if
(
password
===
this
.
password
)
{
return
true
;
}
return
false
;
}
// return `true` if they match, otherwise return `false`
}
const
me
=
new
User
(
{
username
:
'LambdaSchool'
,
password
:
'correcthorsebatterystaple'
,
}
)
;
const
result
=
me
.
checkPassword
(
'correcthorsebatterystaple'
)
;
// should return `true`
/* part 2 */
const
checkPassword
=
function
comparePasswords
(
passwordToCompare
)
{
// recreate the `checkPassword` method that you made on the `User` class
// use `this` to access the object's `password` property.
// do not modify this function's parameters
// note that we use the `function` keyword and not `=>`
if
(
passwordToCompare
===
this
.
password
)
return
true
;
}
;
// invoke `checkPassword` on `me` by explicitly setting the `this` context
// use .call, .apply, and .bind
// .call
me
.
checkPassword
.
call
(
me
,
'correcthorsebatterystaple'
)
;
// .apply
me
.
checkPassword
.
apply
(
me
,
this
.
password
)
;
// .bind
checkPassword
.
bind
(
me
,
this
.
password
)
;
// binds method to comparePasswords
console
.
log
(
checkPassword
(
this
.
password
)
)
;
// returns true
Back
|
FazBrowse Home
|
New Git URL