Skip to content

Commit 12b607d

Browse files
committed
lesson5
1 parent 9bd9123 commit 12b607d

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

lesson5.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Custom Pokemons Implementation
2+
let Pokemons = {
3+
// Method we want to replace
4+
amount() {
5+
// Call to database
6+
},
7+
8+
// Method we want to stay intact
9+
say(str) {
10+
console.log('Your Pokedex says: ', str)
11+
}
12+
}
13+
14+
// Function using Pokemons class
15+
function howsMyCollection() {
16+
const size = Pokemons.amount()
17+
if (size === undefined)
18+
return Pokemons.say('Ooops, not sure how many you have')
19+
if (size < 10)
20+
return Pokemons.say('You only have a few, you need more')
21+
if (size < 50)
22+
return Pokemons.say('You have quite some favorites. Keep going')
23+
return Pokemons.say('You are quite a collector')
24+
}
25+
26+
// Keep an implementation of original implementation for potential use later on
27+
const originalAmount = Pokemons.amount
28+
29+
// Change the output of the amounts function
30+
function stubAmount(amount) {
31+
Pokemons.amount = () => amount
32+
}
33+
34+
// Testing function
35+
function havePokemons(amount) {
36+
stubAmount(amount)
37+
howsMyCollection()
38+
}
39+
40+
// A few tests to show outputs
41+
havePokemons(5) // -- You only have a few, you need more
42+
havePokemons(17) // -- You have quite some favorites. Keep going
43+
havePokemons(100) // -- You are quite a collector

0 commit comments

Comments
 (0)