forked from processing/p5.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
documented-method.js
60 lines (52 loc) · 1.52 KB
/
documented-method.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
59
60
// https://github.com/umdjs/umd/blob/main/templates/returnExports.js
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define([], factory);
} else if (typeof module === 'object' && module.exports) {
module.exports = factory();
} else {
root.DocumentedMethod = factory();
}
}(this, function () {
function extend(target, src) {
Object.keys(src).forEach(function(prop) {
target[prop] = src[prop];
});
return target;
}
function DocumentedMethod(classitem) {
extend(this, classitem);
if (this.overloads) {
// Make each overload inherit properties from their parent
// classitem.
this.overloads = this.overloads.map(function(overload) {
return extend(Object.create(this), overload);
}, this);
if (this.params) {
throw new Error('params for overloaded methods should be undefined');
}
this.params = this._getMergedParams();
}
}
DocumentedMethod.prototype = {
// Merge parameters across all overloaded versions of this item.
_getMergedParams: function() {
const paramNames = {};
const params = [];
this.overloads.forEach(function(overload) {
if (!overload.params) {
return;
}
overload.params.forEach(function(param) {
if (param.name in paramNames) {
return;
}
paramNames[param.name] = param;
params.push(param);
});
});
return params;
}
};
return DocumentedMethod;
}));