init source
This commit is contained in:
+24
@@ -0,0 +1,24 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Wraps a constructor to not need the `new` keyword using a proxy.
|
||||
* Only used for data types.
|
||||
*
|
||||
* @param {Function} Class The class instance to wrap as invocable.
|
||||
* @returns {Proxy} Wrapped class instance.
|
||||
* @private
|
||||
*/
|
||||
function classToInvokable(Class) {
|
||||
return new Proxy(Class, {
|
||||
apply(Target, thisArg, args) {
|
||||
return new Target(...args);
|
||||
},
|
||||
construct(Target, args) {
|
||||
return new Target(...args);
|
||||
},
|
||||
get(target, p) {
|
||||
return target[p];
|
||||
}
|
||||
});
|
||||
}
|
||||
exports.classToInvokable = classToInvokable;
|
||||
Reference in New Issue
Block a user