-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction_create_threeways
More file actions
33 lines (25 loc) · 896 Bytes
/
function_create_threeways
File metadata and controls
33 lines (25 loc) · 896 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
function objectGet(getAccess){ //1. factory function
var myObj = Object.create(objectGet.prototype);
myObj.getAccess = getAccess;
return myObj;
}
objectGet.prototype = { getAccess: function(){
return this.getAccess
}
}
var d = objectGet('data');
function objectGet(getAccess){ //2. constructor function may cause unintended global usage without 'var'
this.getAccess = getAccess;
}
objectGet.prototype = { getAccess: function(){
return this.getAccess;
}
}
var c = new objectGet('data');
function genericFunc(Ctr){ //3. generic function
var myObj = Object.create(Ctr.prototype);
var arg = Array.prototype.slice.call(arguments, 1); //arguments = scope 'this' //1
Ctr.bind(myObj,arg); //deprecated in jQuery 3.0
return myObj;
}
var o = genericFunc(objectGet, 'data');