Last active
January 8, 2017 03:52
-
-
Save marklearst/de5fc69efff14e9c9c0041898f817849 to your computer and use it in GitHub Desktop.
Revisions
-
marklearst renamed this gist
Jan 8, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -29,7 +29,7 @@ console.log( '\n' ); //----------------------------------------- // Passing in an anonymous function as first argument fruits.forEach( function( element, index, array ) { array[index] = '<' + this.tag + '>' array[index] += element array[index] += '</' + this.tag + '>' -
marklearst created this gist
Jan 8, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,41 @@ // Object with div element and base attributes var divElementObj = { tag: 'div', class: 'col-4' } // An Array of Fruits var fruits = [ 'apple', 'pear', 'fig' ] // Logging fruits before forEach is called console.log( fruits ); console.log( '\n' ); //----------------------------------------- // Utility function that wraps text with a <div> // function divWrapper( element, index, arr ) { // array[index] = '<' + this.tag + '>' // array[index] += element // array[index] += '</' + this.tag + '>' // ES6 Template Literal // array[index] = `<${this.tag} class="${this.class}">${element}</${this.tag}>`; // } // Call forEach with and pass in thisDiv as Argument // fruits.forEach( divWrapper, divElementObj ) //----------------------------------------- // Passing in an anonymous function as first argument var newFruits = fruits.forEach( function( element, index, array ) { array[index] = '<' + this.tag + '>' array[index] += element array[index] += '</' + this.tag + '>' // ES6 Template Literal // return `<${this.tag} class="${this.class}">${element}</${this.tag}>`; }, divElementObj ) // After forEach was called on fruits Array. console.log( newFruits )