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:
@ -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"); }
|
||||
}
|
||||
|
||||
}
|
||||
})();
|
||||
```
|
||||
|
@ -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;
|
||||
}
|
||||
```
|
||||
|
Reference in New Issue
Block a user