Skip to content

Commit b0bdc8e

Browse files
committed
allow replacing particular parameters
1 parent 5c7de3d commit b0bdc8e

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

lib/trace.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@
22
var EventEmitter = require('events').EventEmitter;
33
var util = require('util');
44

5-
function extendTrace(object, property) {
5+
function extendTrace(object, property, pos) {
66
var old = object[property];
7-
object[property] = function(x) {
7+
object[property] = function() {
88
var error = new Error();
99
var name = object.constructor.name + '#' + property + '(' +
1010
Array.prototype.slice.call(arguments).map(function(el) {
1111
return util.inspect(el, false, 0);
1212
}).join(', ') + ')';
1313

14-
var last = arguments.length - 1;
15-
var cb = arguments[last];
16-
if (typeof arguments[last] === 'function') {
17-
arguments[last] = function replacement() {
14+
if (typeof pos === 'undefined') pos = -1;
15+
if (pos < 0) pos += arguments.length;
16+
var cb = arguments[pos];
17+
if (typeof arguments[pos] === 'function') {
18+
arguments[pos] = function replacement() {
1819
try {
1920
return cb.apply(this, arguments);
2021
} catch (err) {

0 commit comments

Comments
 (0)