File tree Expand file tree Collapse file tree 1 file changed +16
-13
lines changed Expand file tree Collapse file tree 1 file changed +16
-13
lines changed Original file line number Diff line number Diff line change @@ -4,19 +4,22 @@ const app = document.getElementById('app');
4
4
app . innerHTML = '<h1>JavaScript Basics</h1>' ;
5
5
6
6
// --------------------------------------------------
7
- // Function IIFE immediatley Invoked Function Expression
7
+ // Functions and Callbacks
8
8
// --------------------------------------------------
9
9
10
- // expression by wrapping in parens and calling it immediately
11
- // like JQuery
12
- const carPartId = ( function ( id ) {
13
- const theId = `CAR_PART_${ id } ` ;
14
- return function ( name ) {
15
- return `${ theId } _${ name } ` ;
16
- } ;
17
- } ) ( 'XAT5461' ) ;
10
+ function carPartId ( name , fn ) {
11
+ const theId = `CAR_PART_XAT5461` ;
12
+ fn ( theId ) ;
13
+ }
18
14
19
- // Encapsulation of ID
20
- console . log ( carPartId ( 'LEFT_DOOR' ) ) ;
21
- console . log ( carPartId ( 'RIGHT_DOOR' ) ) ;
22
- console . log ( carPartId ( 'WINDSCREEN' ) ) ;
15
+ carPartId ( 'LEFT_DOOR' , function ( id ) {
16
+ console . log ( `Car Part Id: ${ id } ` ) ;
17
+ } ) ;
18
+
19
+ /**
20
+ * Here the carPartId calls the function
21
+ * The id is created
22
+ * the passed fn is then called with the id
23
+ * the original caller is then able to log the ID
24
+ * CALLBACK
25
+ */
You can’t perform that action at this time.
0 commit comments