Methods
-
<static> getPatchesByCaller( name )
-
Description
Returns all the patches done by a specific caller
Parameters
Name Type Description name
string Name of the patch caller
Details
-
<static> unpatchAll( patches )
-
Description
Unpatches all patches passed, or when a string is passed unpatches all patches done by that specific caller.
Parameters
Name Type Description patches
Array | string Either an array of patches to unpatch or a caller name
Details
-
<static> before( caller, moduleToPatch, functionName, callback, options ) → {module:Patcher~unpatch}
-
Description
This method patches onto another function, allowing your code to run beforehand. Using this, you are also able to modify the incoming arguments before the original method is run.
Parameters
Name Type Description caller
string Name of the caller of the patch function. Using this you can undo all patches with the same name using module:Patcher.unpatchAll. Use
""
if you don't care.moduleToPatch
object Object with the function to be patched. Can also patch an object's prototype.
functionName
string Name of the method to be patched
callback
module:Patcher~patchCallback Function to run before the original method
options
object Object used to pass additional options.
Name Type Attributes Default Description displayName
string <optional> You can provide meaningful name for class/object provided in
what
param for logging purposes. By default, this function will try to determine name automatically.forcePatch
boolean <optional> true Set to
true
to patch even if the function doesnt exist. (Adds noop function in place).Returns
Details
-
<static> after( caller, moduleToPatch, functionName, callback, options ) → {module:Patcher~unpatch}
-
Description
This method patches onto another function, allowing your code to run after. Using this, you are also able to modify the return value, using the return of your code instead.
Parameters
Name Type Description caller
string Name of the caller of the patch function. Using this you can undo all patches with the same name using module:Patcher.unpatchAll. Use
""
if you don't care.moduleToPatch
object Object with the function to be patched. Can also patch an object's prototype.
functionName
string Name of the method to be patched
callback
module:Patcher~patchCallback Function to run instead of the original method
options
object Object used to pass additional options.
Name Type Attributes Default Description displayName
string <optional> You can provide meaningful name for class/object provided in
what
param for logging purposes. By default, this function will try to determine name automatically.forcePatch
boolean <optional> true Set to
true
to patch even if the function doesnt exist. (Adds noop function in place).Returns
Details
-
<static> instead( caller, moduleToPatch, functionName, callback, options ) → {module:Patcher~unpatch}
-
Description
This method patches onto another function, allowing your code to run instead. Using this, you are also able to modify the return value, using the return of your code instead.
Parameters
Name Type Description caller
string Name of the caller of the patch function. Using this you can undo all patches with the same name using module:Patcher.unpatchAll. Use
""
if you don't care.moduleToPatch
object Object with the function to be patched. Can also patch an object's prototype.
functionName
string Name of the method to be patched
callback
module:Patcher~patchCallback Function to run after the original method
options
object Object used to pass additional options.
Name Type Attributes Default Description displayName
string <optional> You can provide meaningful name for class/object provided in
what
param for logging purposes. By default, this function will try to determine name automatically.forcePatch
boolean <optional> true Set to
true
to patch even if the function doesnt exist. (Adds noop function in place).Returns
Details
-
<static> pushChildPatch( caller, moduleToPatch, functionName, callback, options ) → {module:Patcher~unpatch}
-
Description
This method patches onto another function, allowing your code to run before, instead or after the original function. Using this you are able to modify the incoming arguments before the original function is run as well as the return value before the original function actually returns.
Parameters
Name Type Description caller
string Name of the caller of the patch function. Using this you can undo all patches with the same name using module:Patcher.unpatchAll. Use
""
if you don't care.moduleToPatch
object Object with the function to be patched. Can also patch an object's prototype.
functionName
string Name of the method to be patched
callback
module:Patcher~patchCallback Function to run after the original method
options
object Object used to pass additional options.
Name Type Attributes Default Description type
string <optional> after Determines whether to run the function
before
,instead
, orafter
the original.displayName
string <optional> You can provide meaningful name for class/object provided in
what
param for logging purposes. By default, this function will try to determine name automatically.forcePatch
boolean <optional> true Set to
true
to patch even if the function doesnt exist. (Adds noop function in place).Returns
Details
Type Definitions
-
unpatch()
-
Description
Function with no arguments and no return value that may be called to revert changes made by module:Patcher, restoring (unpatching) original method.
Details
-
patchCallback( thisObject, arguments, extraValue ) → {*}
-
Description
A callback that modifies method logic. This callback is called on each call of the original method and is provided all data about original call. Any of the data can be modified if necessary, but do so wisely.
The third argument for the callback will be
undefined
forbefore
patches.originalFunction
forinstead
patches andreturnValue
forafter
patches.Parameters
Name Type Description thisObject
object this
in the context of the original function.arguments
arguments The original arguments of the original function.
extraValue
function | * For
instead
patches, this is the original function from the module. Forafter
patches, this is the return value of the function.Returns
Details