aboutsummaryrefslogtreecommitdiff
path: root/src/extensions/ArrayExtensions.ts
diff options
context:
space:
mode:
authorSam Wilkins <samwilkins333@gmail.com>2019-11-19 11:28:49 -0500
committerSam Wilkins <samwilkins333@gmail.com>2019-11-19 11:28:49 -0500
commit3f86ea5556ab7a1fc13cd9c74ef4305f2f5cd778 (patch)
tree4d13f3401ecc80fb5bce22d2a3382545102fda7f /src/extensions/ArrayExtensions.ts
parent611bb858265b6667f2b7db858d183cea16f273aa (diff)
parentd259cf7b16e64794bc12ae420f9b512a75eee46c (diff)
merged with master
Diffstat (limited to 'src/extensions/ArrayExtensions.ts')
-rw-r--r--src/extensions/ArrayExtensions.ts34
1 files changed, 29 insertions, 5 deletions
diff --git a/src/extensions/ArrayExtensions.ts b/src/extensions/ArrayExtensions.ts
index 422a10dbc..8e125766d 100644
--- a/src/extensions/ArrayExtensions.ts
+++ b/src/extensions/ArrayExtensions.ts
@@ -1,13 +1,37 @@
-function Assign() {
+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() {
+ Object.defineProperty(Array.prototype, this.property, {
+ value: this.body,
+ enumerable: false
+ });
+ }
- Array.prototype.lastElement = function <T>() {
+}
+
+/**
+ * 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;
}
- const last: T = this[this.length - 1];
- return last;
- };
+ return this[this.length - 1];
+ })
+];
+function Assign() {
+ extensions.forEach(extension => extension.assign());
}
export { Assign }; \ No newline at end of file