MCPcopy Index your code
hub / github.com/amasad/debug_utils / wrapMethod

Function wrapMethod

du.js:178–208  ·  view source on GitHub ↗

* Wraps a method with a debugger or logger statement. * * @param {object} object * @param {string} methodName * @param {boolean} isLog * @private

(object, methodName, isLog)

Source from the content-addressed store, hash-verified

176 */
177
178function wrapMethod(object, methodName, isLog) {
179 assert(
180 typeof object === 'object' &&
181 object && typeof object[methodName] === 'function',
182 'Illegal object or failed to find method.'
183 );
184
185 var method = object[methodName];
186
187 wrappedMethods.push({
188 object: object,
189 method: method
190 });
191
192 var slice = [].slice;
193 var replacement;
194
195 if (isLog) {
196 replacement = function() {
197 console.log(arguments);
198 return method.apply(this, slice.call(arguments));
199 };
200 } else {
201 replacement = function() {
202 debugger;
203 return method.apply(this, slice.call(arguments));
204 };
205 }
206
207 object[methodName] = replacement;
208}
209
210/**
211 * Wraps a method with a debugger statement.

Callers 2

$dumFunction · 0.85
$dumlFunction · 0.85

Calls 1

assertFunction · 0.85

Tested by

no test coverage detected