-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #465 from mStirner/dev
Working on issues (forward v3)
- Loading branch information
Showing
19 changed files
with
1,237 additions
and
215 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* @function injectMethod | ||
* Add a method to a given object into the prototype | ||
* Default values are set to the exact same values when the method would be defined in the object/class body | ||
* | ||
* @param {Object} obj Object to add property to | ||
* @param {String} prop The property name | ||
* @param {*} value Value of the property | ||
* @param {Object} [options={}] Property descriptor options | ||
* @param {Boolean} [options.writable=true] | ||
* @param {Boolean} [options.enumerable=false] | ||
* @param {Boolean} [options.configurable=true] | ||
* | ||
* @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty#description | ||
*/ | ||
|
||
function injectMethod(obj, prop, value, options = {}) { | ||
|
||
if (!(value instanceof Function)) { | ||
throw new TypeError(`Value must be a function, received ${typeof value}`); | ||
} | ||
|
||
// NOTE: Setting on prototype of given object, breaks iface.bridge()... | ||
// Object.defineProperty(Object.getPrototypeOf(obj), prop, { | ||
Object.defineProperty(obj, prop, { | ||
value, | ||
writable: true, | ||
enumerable: false, | ||
configurable: true, | ||
...options | ||
}); | ||
|
||
} | ||
|
||
module.exports = injectMethod; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.