-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
89 lines (73 loc) · 2.05 KB
/
index.js
File metadata and controls
89 lines (73 loc) · 2.05 KB
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
/*!
* Method Missing.
*
* Main test file.
* @author Jarrad Seers <jarrad@seers.me>
* @created 29/03/2017 NZDT
*/
const MethodMissing = require('../');
class Simple extends MethodMissing {
iExist(str) {
console.log(`I do exist ${str}.`);
return this;
}
__call(name, args) {
console.log(`The method '${name}' was called with:`, args);
return this;
}
static __call(name, args) {
console.log(`The method '${name}' was called with:`, args);
}
}
Simple = MethodMissing.static(Simple);
const simple = new Simple();
simple.nonExistent('hello');
simple.iExist('world');
Simple.nonExistentStatic('hey');
// The method 'nonExistent' was called with: { '0': 'hello' }
// I do exist world.
// The method 'nonExistentStatic' was called with: { '0': 'hey' }
class Test extends MethodMissing {
constructor() {
super('missing');
}
missing(name, args) {
console.log(`The method '${name}' was called with:`, args);
return this;
}
static missing(name, args) {
console.log(`The method '${name}' was called with:`, args);
}
}
Test = MethodMissing.static(Test, 'missing');
const test = new Test();
test.nonExistent('hello');
test.nonExistentStatic('world');
// The method 'nonExistentStatic' was called with: { '0': 'hey' }
// The method 'nonExistent' was called with: { '0': 'hello' }
// The method 'nonExistentStatic' was called with: { '0': 'world' }
class RealSimple extends MethodMissing {
__call(name, [...args]) {
console.log(`The method '${name}' was called with:`, args);
return this;
}
}
new RealSimple().nonExistent('Hello!');
// The method 'nonExistent' was called with: { '0': 'Hello!' }
class Args extends MethodMissing {
__call(name, [...args]) {
console.log(`The method '${name}' was called with:`, args);
return this;
}
}
new Args().say('hello', 'world!');
// The method 'say' was called with: [ 'hello', 'world!' ]
const object = MethodMissing.static({
one () {
console.log('hey there');
},
}, (name) => {
console.log(`Sorry, method '${name}' doesn't exist.`);
});
object.one();
object.two();