From 58e70055737ae6b96cea582ef40247ae6b97225b Mon Sep 17 00:00:00 2001 From: xJuggl3r <50606269+xJuggl3r@users.noreply.github.com> Date: Fri, 19 Jul 2019 17:03:21 -0400 Subject: [PATCH] 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 --- .../use-an-iife-to-create-a-module/index.md | 18 ++++++++++++++++++ .../index.md | 11 +++++++++++ 2 files changed, 29 insertions(+) diff --git a/guide/english/certifications/javascript-algorithms-and-data-structures/object-oriented-programming/use-an-iife-to-create-a-module/index.md b/guide/english/certifications/javascript-algorithms-and-data-structures/object-oriented-programming/use-an-iife-to-create-a-module/index.md index 4bacba9572..ecc1f147ec 100644 --- a/guide/english/certifications/javascript-algorithms-and-data-structures/object-oriented-programming/use-an-iife-to-create-a-module/index.md +++ b/guide/english/certifications/javascript-algorithms-and-data-structures/object-oriented-programming/use-an-iife-to-create-a-module/index.md @@ -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"); } + } + + } +})(); +``` diff --git a/guide/english/certifications/javascript-algorithms-and-data-structures/object-oriented-programming/use-closure-to-protect-properties-within-an-object-from-being-modified-externally/index.md b/guide/english/certifications/javascript-algorithms-and-data-structures/object-oriented-programming/use-closure-to-protect-properties-within-an-object-from-being-modified-externally/index.md index c675927909..158d35b6e0 100644 --- a/guide/english/certifications/javascript-algorithms-and-data-structures/object-oriented-programming/use-closure-to-protect-properties-within-an-object-from-being-modified-externally/index.md +++ b/guide/english/certifications/javascript-algorithms-and-data-structures/object-oriented-programming/use-closure-to-protect-properties-within-an-object-from-being-modified-externally/index.md @@ -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; +} +```