-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobjectSuperMethod.js
More file actions
37 lines (30 loc) · 924 Bytes
/
Copy pathobjectSuperMethod.js
File metadata and controls
37 lines (30 loc) · 924 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
Object.prototype.super = function(name){
var that = this;
var func = that[name];
return function(){
return func.apply(that,arguments);
}
}
//For Eg: Where to use !
var mammal = function(spex){
this.salutation = "";
this.get_name = function(){
return (this.salutation+" "+spex.name +" is my name, and you are gentleman");
}
return this;
}
var coolerMammal = function(spex){
var that = mammal(spex);
var prev = that.super("get_name");
that.get_name = function(){
return "hey yo! "+prev()+", now lets go party";
};
return that;
}
var human = coolerMammal({name: "Mitch"});
human.get_name();
// Output: "hey yo! Mitch is my name, and you are gentleman, now lets go party"
blackGuy.salutation = "Mister";
// Out: "Mister"
blackGuy.get_name();
// "hey yo! Mister Mitch is my name, and you are gentleman, now lets go party"