aboutsummaryrefslogtreecommitdiff
path: root/src/extensions/ArrayExtensions.ts
diff options
context:
space:
mode:
authorab <abdullah_ahmed@brown.edu>2019-10-15 19:28:57 -0400
committerab <abdullah_ahmed@brown.edu>2019-10-15 19:28:57 -0400
commit3fc0d321b3b3ee09955c35e0a7bb260153b013e1 (patch)
treee7f4a33e5355cb9c1592d0a6a2d15f3d4e626e7c /src/extensions/ArrayExtensions.ts
parent814838063b6bbdf8dc813eb601de8da6b4ae0320 (diff)
fixed fatal startup issue
Diffstat (limited to 'src/extensions/ArrayExtensions.ts')
-rw-r--r--src/extensions/ArrayExtensions.ts35
1 files changed, 30 insertions, 5 deletions
diff --git a/src/extensions/ArrayExtensions.ts b/src/extensions/ArrayExtensions.ts
index 422a10dbc..43cda97e6 100644
--- a/src/extensions/ArrayExtensions.ts
+++ b/src/extensions/ArrayExtensions.ts
@@ -1,13 +1,38 @@
-function Assign() {
- Array.prototype.lastElement = function <T>() {
+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
+ });
+ }
+
+}
+
+/**
+ * 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