-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctional.js
More file actions
46 lines (32 loc) Β· 727 Bytes
/
functional.js
File metadata and controls
46 lines (32 loc) Β· 727 Bytes
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
var Button = function() {
var obj = {};
obj.count = 0;
obj.press = function() {
this.count++;
}
obj.pressCount = function() {
return this.count;
};
return obj;
}
var myButton = Button();
console.log('Button Obj:', myButton);
myButton.press();
myButton.press();
//WILL NOT overwrite method..
Button.press = function() {
this.count += 5;
};
myButton.press();
console.log('Button Press Count:', myButton.pressCount());
//Create a new class to overwrite method..
var newButton = function(){
var obj = Object.create(Button());
obj.press = function() {
this.count += 5;
}
return obj;
};
myNewButton = newButton();
myNewButton.press();
console.log('New Button Press Count:', myNewButton.pressCount());