forked from rdblakemore/JavaScript-Interface
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterface-sample.js
58 lines (54 loc) · 1.59 KB
/
interface-sample.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
/**
* Define interface to return a new Interface object
* @param {JSON Object} implementation Implementations of interface functions.
* @return
*/
var iThing = function(implementation) {
return new Interface({
doStuff: function(param) {},
doMoreStuff: function(param1, param2) {},
doStuffWithoutParams: function() {},
implementation: implementation,
type: "iThing"
});
};
var a = new iThing({
doStuff: function(param) {
alert("a.doStuff with parameter value ".concat(param));
},
doMoreStuff: function(param1, param2) {
alert("a.doMoreStuff with parameter values ".concat(param1)
.concat(",")
.concat(param2));
},
doStuffWithoutParams: function() {
return "a.doStuffWithoutParams";
}
});
a.doStuff("foo"); //alerts "foo"
// Throws error
// "The implementation of iThing.doMoreStuff does not have the correct number of arguments."
var b = new iThing({
doStuff: function(param) {
alert("b.doStuff with parameter value ".concat(param));
},
doMoreStuff: function(param1) {
alert("b.doMoreStuff with parameter values ".concat(param1)
.concat(",")
.concat(param2));
},
doStuffWithoutParams: function() {
return "b.doStuffWithoutParams";
}
});
// Throws error "iThing.doStuffWithoutParams has not been implemented."
var c = new iThing({
doStuff: function(param) {
alert("c.doStuff with parameter value ".concat(param));
},
doMoreStuff: function(param1, param2) {
alert("c.doMoreStuff with parameter values ".concat(param1)
.concat(",")
.concat(param2));
}
});