diff options
author | Sam Wilkins <samwilkins333@gmail.com> | 2019-10-15 18:35:56 -0400 |
---|---|---|
committer | Sam Wilkins <samwilkins333@gmail.com> | 2019-10-15 18:35:56 -0400 |
commit | 4e65c84c768da1eabeca552df54ea1ed78812f8e (patch) | |
tree | 379b7b9a30fa8b061d6ba87dbdd065a1e84fee9c /src | |
parent | 33811c112c7e479813908ba10f72813954a3e289 (diff) |
fixed fatal mobx extension-related error, still can use extensions
Diffstat (limited to 'src')
-rw-r--r-- | src/extensions/ArrayExtensions.ts | 34 |
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 |