-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path26_createModuleWithIIFE.js
More file actions
47 lines (43 loc) · 1.14 KB
/
26_createModuleWithIIFE.js
File metadata and controls
47 lines (43 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Use an IIFE to Create a Module
/* Immediately Invoked Function Expressions can be used
to package a module like a set of mixins */
let motionModule = (function () {
return {
glideMixin: function(obj) {
obj.glide = function() {
console.log("Gliding on the water");
};
},
flyMixin: function(obj) {
obj.fly = function() {
console.log("Flying, wooosh!");
};
}
}
})();
function Bird() {
let hatchedEgg = 10;
this.getHatchedEggCount = function() {
return hatchedEgg;
};
}
let ducky = new Bird();
motionModule.glideMixin(ducky);
ducky.glide() // Gliding on the water
/* Create a module named funModule to wrap the two mixins
isCuteMixin and singMixin. funModule should return
an object. */
let funModule = (function () {
return {
isCuteMixin: function(obj) {
obj.isCute = function() {
return true;
};
},
singMixin: function(obj) {
obj.sing = function() {
console.log("Singing to an awesome tune");
};
}
}
})();