Add ES6 syntax to Challenge' solution (#36367)

* ES6 syntax

Added ES6 syntax to challenge' solution.

* Add ES6 solution to challenge

An optional way to solve the challenge using ES6 arrow functions
This commit is contained in:
xJuggl3r
2019-07-19 17:03:21 -04:00
committed by Quincy Larson
parent 42181af79b
commit 58e7005573
2 changed files with 29 additions and 0 deletions

View File

@ -45,3 +45,21 @@ let funModule = (function() {
})(); })();
``` ```
### Solution 2
If using ES6, the same can be rewritten as:
```javascript
let funModule = ( () => {
return {
isCuteMixin: (obj) => {
obj.isCute = () => { true; };
},
singMixin: (obj) => {
obj.sing = () => { console.log("Singing to an awesome tune"); }
}
}
})();
```

View File

@ -21,3 +21,14 @@ function Bird() {
} }
``` ```
### Solution 2
In ES6 syntax we can make the function a bit less verbose:
```
function Bird() {
let weight = 15;
this.getWeight = () => weight;
}
```