blob: a50fb330f045a622e3d73cc5cfc98f22bf1b8ae3 (
plain)
| 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
 | export default class ArrayExtension {
    private readonly property: string;
    private readonly body: <T>(this: Array<T>) => any;
    constructor(property: string, body: <T>(this: Array<T>) => any) {
        this.property = property;
        this.body = body;
    }
    assign() {
        // eslint-disable-next-line no-extend-native
        Object.defineProperty(Array.prototype, this.property, {
            value: this.body,
            enumerable: false,
        });
    }
}
/**
 * IMPORTANT: Any extension you add here *must* have a corresponding type definition
 * in the Array<T> interface in ./General/ExtensionsTypings.ts. Otherwise,
 * Typescript will not recognize your new function.
 */
const extensions = [
    new ArrayExtension('lastElement', function () {
        if (!this.length) {
            return undefined;
        }
        return this[this.length - 1];
    }),
];
function Assign() {
    extensions.forEach(extension => extension.assign());
}
export { Assign };
 |