Last active
May 15, 2018 04:35
-
-
Save davedub/e6d88ebdbea640bfbb55ad986a1f3393 to your computer and use it in GitHub Desktop.
Arrow function to push array into new array created by davedub - https://repl.it/@davedub/Arrow-function-to-push-array-into-new-array
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 characters
| // solution for "writing arrow functions" exercise | |
| // https://repl.it/student/classrooms/27654 | |
| const example1 = { | |
| stuff: [1, 2, 3, 4, 5, 6, 7], | |
| otherBits: [], | |
| addStuff: function() { | |
| this.stuff.forEach(function(thing) { | |
| this.otherBits.push(thing) | |
| }) | |
| } | |
| } | |
| // example1.addStuff() | |
| // console.log(example1.otherBits) | |
| // returns error: "this.otherBits undefined" | |
| const example2 = { | |
| stuff: [1, 2, 3, 4, 5, 6, 7], | |
| otherBits: [], | |
| addStuff: function() { | |
| this.stuff.forEach((i) => this.otherBits.push(i) | |
| )} | |
| } | |
| example2.addStuff() | |
| console.log(example2.otherBits) | |
| // [ 1, 2, 3, 4, 5, 6, 7 ] | |
| // => undefined |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment