-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
94 lines (74 loc) · 1.49 KB
/
main.js
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/**
* Object.create
*/
// var dog = {
// color: 'red',
// wag: function(){
// console.log('wagging is awesome');
// }
// };
//
// // Object.create()
// var objectCreate = function(o){
// function F(){}
// F.prototype = o;
// return new F();
// };
//
// var kepler = Object.create(dog);
// var ozzy = Object.create(dog);
// ozzy.color = 'black';
// console.log(kepler.color);
// ozzy.wag();
/*
* Constructor Configs
*/
function CuteAnimal (config) {
config = config || {};
var defaults = {
color: 'brown',
status: 'normal',
hungry: true
};
// $.extend(this, defaults, config);
var settings = Object.assign({}, defaults, config);
this.color = settings.color;
this.status = settings.status;
this.hungry = settings.hungry;
this.wag = function(){
};
}
/**
* Closures
*/
function showName(firstName){
function buildName(lastName){
console.log(firstName, lastName);
}
return buildName;
}
var nameBuilder = showName('Dan');
nameBuilder('Dietz');
/**
* Currying and Partial Applications
*/
// function add(num1, num2){
// return num1 + num2;
// }
function add(num1){
var title = 'Your answer is: ';
function addSecondNumber(num2){
return title + (num1 + num2);
}
return addSecondNumber;
}
var addNine = add(9);
console.log(addNine(10));
console.log(addNine(20));
var addTen = add(10);
console.log(addTen(10));
console.log(addTen(20));
var addFive = add(5);
console.log(addFive(5));
console.log(addFive(150));
console.log(add(3)(3));