1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | var _a, _b;
|
11 | const nativeInsertBefore = Node.prototype.insertBefore;
|
12 | const nativeGetFirstChild = (_b =
|
13 |
|
14 |
|
15 | (_a = Object.getOwnPropertyDescriptor(Node.prototype, 'firstChild')) === null || _a === void 0 ? void 0 : _a.get) !== null && _b !== void 0 ? _b :
|
16 |
|
17 | function () { return this.firstChild; };
|
18 | const installPrepend = (constructor) => {
|
19 | const prototype = constructor.prototype;
|
20 | if (prototype.hasOwnProperty('prepend')) {
|
21 | return;
|
22 | }
|
23 | Object.defineProperty(prototype, 'prepend', {
|
24 | configurable: true,
|
25 | enumerable: true,
|
26 | writable: true,
|
27 | value: function prepend(...args) {
|
28 | const firstChild = nativeGetFirstChild.call(this);
|
29 | for (const arg of args) {
|
30 | const newNode = typeof arg === 'string' ? document.createTextNode(arg) : arg;
|
31 | nativeInsertBefore.call(this, newNode, firstChild);
|
32 | }
|
33 | }
|
34 | });
|
35 | };
|
36 | installPrepend(Document);
|
37 | installPrepend(DocumentFragment);
|
38 | installPrepend(Element);
|
39 |
|
\ | No newline at end of file |