File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -9,8 +9,20 @@ app.innerHTML = '<h1>JavaScript Basics</h1>';
9
9
10
10
function makeCarPartId ( id ) {
11
11
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
+ } ;
13
16
}
14
17
15
18
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' ) ) ;
You can’t perform that action at this time.
0 commit comments