UNPKG

1.8 kBJavaScriptView Raw
1
2export default {
3
4 async setup () {
5
6 if (window.Reflect === undefined) {
7 window.Reflect = window.Reflect || {};
8 window.Reflect.construct = function (parent, args, child) {
9 const target = child === undefined ? parent : child;
10 const prototype = target.prototype || Object.prototype;
11 const copy = Object.create(prototype);
12 return Function.prototype.apply.call(parent, copy, args) || copy;
13 };
14 }
15
16 },
17
18 define (name, constructor) {
19 constructor = constructor || function () {};
20
21 // const properties = Object.assign({}, constructor);
22 // const prototypes = Object.assign({}, constructor.prototype);
23 // const properties = Object.getOwnPropertyDescriptors(constructor);
24
25 // delete properties.name;
26 // delete properties.caller;
27 // delete properties.length;
28 // delete properties.arguments;
29 // delete properties.prototype;
30
31 const construct = function () {
32 const instance = window.Reflect.construct(HTMLElement, [], this.constructor);
33 constructor.call(instance);
34 return instance;
35 };
36
37 const prototypes = Object.getOwnPropertyDescriptors(constructor.prototype);
38
39 construct.prototype = Object.create(HTMLElement.prototype);
40
41 // Object.assign(construct, properties);
42 // Object.assign(construct.prototype, prototypes);
43 // Object.defineProperties(construct, properties);
44 Object.defineProperties(construct.prototype, prototypes);
45 Object.defineProperty(construct.prototype, 'constructor', { enumerable: false, writable: true, value: construct });
46
47 window.customElements.define(name, construct);
48 }
49
50}