Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5e45635

Browse files
committed
Question 74
1 parent eaf14fa commit 5e45635

File tree

1 file changed

+67
-3
lines changed

1 file changed

+67
-3
lines changed

‎README.md‎

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2948,9 +2948,9 @@ getYear();
29482948
```
29492949
29502950
- A: undefined - undefined - 2021
2951-
- B: undefined - 2021 - 2021
2952-
- C: 2021 - undefined - 2021
2953-
- D: 2021 - 2021 - 2021
2951+
- B: undefined - 2021 - 2021
2952+
- C: 2021 - undefined - 2021
2953+
- D: 2021 - 2021 - 2021
29542954
29552955
<details><summary><b>Answer</b></summary>
29562956
<p>
@@ -2967,3 +2967,67 @@ Be aware of the `setTimeout` method, which will create a separated context that
29672967
29682968
</p>
29692969
</details>
2970+
2971+
###### 74. What's the output?
2972+
2973+
```javascript
2974+
2975+
class handleCovid {
2976+
constructor(start) {
2977+
this.start = start;
2978+
}
2979+
2980+
calculate(someValue) {
2981+
this.start = this.start + someValue;
2982+
return this.start;
2983+
}
2984+
2985+
vaccine() {
2986+
++this.start;
2987+
return this;
2988+
}
2989+
2990+
delaying() {
2991+
++this.start;
2992+
return this;
2993+
}
2994+
2995+
static getFinal(result) {
2996+
return result * 2;
2997+
}
2998+
}
2999+
3000+
const now = new handleCovid(2019);
3001+
3002+
console.log(
3003+
handleCovid.getFinal(now.vaccine().delaying().calculate(2020))
3004+
);
3005+
```
3006+
3007+
- A: 2019
3008+
- B: 8082
3009+
- C: 8080
3010+
- D: 8084
3011+
3012+
<details><summary><b>Answer</b></summary>
3013+
<p>
3014+
3015+
#### Answer: B
3016+
3017+
The code snippet above is ugly and sounds complicated at first. Yet, you might encounter a situation when some good "take away" messages might be given. The flow of the code is not hard to understand, I suppose.
3018+
3019+
First, a function in JavaScript can accept another function as its parameter. With regard to the `static` keyword, it means we can directly call a static method in the form of `className.staticmethod` without invoking the object created by the normal way `new ClassName`.
3020+
3021+
Besides, you might want to have a look at how we chain more than one method together. That is possible if these methods `return this`.
3022+
3023+
Now let break it down:
3024+
3025+
- `calculate(2020)` --> 2019 +たす 2020 = 4019;
3026+
- `delaying().calculate(2020)` --> 4020;
3027+
- `now.vaccine().delaying().calculate(2020)` --> 4021;
3028+
- `handleCovid.getFinal(now.vaccine().delaying().calculate(2020)` --> 4021*2 = 8082;
3029+
3030+
So the correct answer is B.
3031+
3032+
</p>
3033+
</details>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /