-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathclasses.js
More file actions
48 lines (32 loc) · 1.7 KB
/
classes.js
File metadata and controls
48 lines (32 loc) · 1.7 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
const util = require('util');
const EventEmitter = require('events');
function MyStream() {
EventEmitter.call(this);
}
util.inherits(MyStream, EventEmitter);
MyStream.prototype.write = (data) => this.emit('data', data);
function MyOtherStream() { /* use=moduleImport("classes").getMember("exports").getMember("MyOtherStream").getInstance() */
EventEmitter.call(this);
}
util.inherits(MyOtherStream, EventEmitter);
MyOtherStream.prototype.write = function (data) { /* use=moduleImport("classes").getMember("exports").getMember("MyOtherStream").getInstance() */
this.emit('data', data);
return this;
};
MyOtherStream.prototype.instanceProp = 1; /* def=moduleImport("classes").getMember("exports").getMember("MyOtherStream").getInstance().getMember("instanceProp") */
MyOtherStream.classProp = 1; /* def=moduleImport("classes").getMember("exports").getMember("MyOtherStream").getMember("classProp") */
module.exports.MyOtherStream = MyOtherStream;
// function-style class without .prototype reference
function MyThirdStream() { /* use=moduleImport("classes").getMember("exports").getMember("MyThirdStream").getInstance() */
}
let instance = new MyThirdStream(); /* use=moduleImport("classes").getMember("exports").getMember("MyThirdStream").getInstance() */
module.exports.MyThirdStream = MyThirdStream;
// function-style class without .prototype reference (through global variable)
(function(f) {
foo.bar = function() { /* use=moduleImport("classes").getMember("exports").getMember("bar").getInstance() */
}
})(foo = foo || {});
(function(f) {
let x = new f.bar(); /* use=moduleImport("classes").getMember("exports").getMember("bar").getInstance() */
})(foo = foo || {});
module.exports.bar = foo.bar;