Skip to content

Commit 14dce18

Browse files
committed
internal function returned for replicated calls
1 parent 0524928 commit 14dce18

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/index.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,20 @@ app.innerHTML = '<h1>JavaScript Basics</h1>';
99

1010
function makeCarPartId(id) {
1111
const theId = `CAR_PART_${id}`;
12-
return theId;
12+
// internal function has access to the function scoped vars.
13+
return function(name) {
14+
return `${theId}_${name.toUpperCase()}`
15+
};
1316
}
1417

1518
const carPartId = makeCarPartId('x90wece998');
16-
console.log(carPartId);
19+
// the function returns access to the inner function so we can call both as a cascading call
20+
console.log(carPartId('Left_Door'));
21+
console.log(carPartId('Right_Door'));
22+
console.log(carPartId('Windscreen'));
23+
24+
const anotherCarPartId = makeCarPartId('d20399df');
25+
// the function returns access to the inner function so we can call both as a cascading call
26+
console.log(anotherCarPartId('Left_Door'));
27+
console.log(anotherCarPartId('Right_Door'));
28+
console.log(anotherCarPartId('Windscreen'));

0 commit comments

Comments
 (0)