Methods
-
<static> getPatchesByCaller( name )
-
Description
Returns all the patches done by a specific caller
Parameters
Name Type Description namestring 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 patchesArray | 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 callerstring 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.moduleToPatchobject Object with the function to be patched. Can also patch an object's prototype.
functionNamestring Name of the method to be patched
callbackmodule:Patcher~patchCallback Function to run before the original method
optionsobject Object used to pass additional options.
Name Type Attributes Default Description displayNamestring <optional> You can provide meaningful name for class/object provided in
whatparam for logging purposes. By default, this function will try to determine name automatically.forcePatchboolean <optional> true Set to
trueto 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 callerstring 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.moduleToPatchobject Object with the function to be patched. Can also patch an object's prototype.
functionNamestring Name of the method to be patched
callbackmodule:Patcher~patchCallback Function to run instead of the original method
optionsobject Object used to pass additional options.
Name Type Attributes Default Description displayNamestring <optional> You can provide meaningful name for class/object provided in
whatparam for logging purposes. By default, this function will try to determine name automatically.forcePatchboolean <optional> true Set to
trueto 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 callerstring 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.moduleToPatchobject Object with the function to be patched. Can also patch an object's prototype.
functionNamestring Name of the method to be patched
callbackmodule:Patcher~patchCallback Function to run after the original method
optionsobject Object used to pass additional options.
Name Type Attributes Default Description displayNamestring <optional> You can provide meaningful name for class/object provided in
whatparam for logging purposes. By default, this function will try to determine name automatically.forcePatchboolean <optional> true Set to
trueto 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 callerstring 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.moduleToPatchobject Object with the function to be patched. Can also patch an object's prototype.
functionNamestring Name of the method to be patched
callbackmodule:Patcher~patchCallback Function to run after the original method
optionsobject Object used to pass additional options.
Name Type Attributes Default Description typestring <optional> after Determines whether to run the function
before,instead, orafterthe original.displayNamestring <optional> You can provide meaningful name for class/object provided in
whatparam for logging purposes. By default, this function will try to determine name automatically.forcePatchboolean <optional> true Set to
trueto 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
undefinedforbeforepatches.originalFunctionforinsteadpatches andreturnValueforafterpatches.Parameters
Name Type Description thisObjectobject thisin the context of the original function.argumentsarguments The original arguments of the original function.
extraValuefunction | * For
insteadpatches, this is the original function from the module. Forafterpatches, this is the return value of the function.Returns
Details