diff --git a/src/raven.js b/src/raven.js index 94cfd4340d9b..f43fe448f6f1 100644 --- a/src/raven.js +++ b/src/raven.js @@ -156,14 +156,23 @@ var Raven = { options = undefined; } - return function() { - try { - return func.apply(this, arguments); - } catch(e) { - Raven.captureException(e, options); - throw e; + var property, + wrappedFunction = function() { + try { + func.apply(this, arguments); + } catch(e) { + Raven.captureException(e, options); + throw e; + } + }; + + for (property in func) { + if (func.hasOwnProperty(property)) { + wrappedFunction[property] = func[property]; } - }; + } + + return wrappedFunction; }, /* diff --git a/test/raven.test.js b/test/raven.test.js index cac13620159f..b802cd7d63bb 100644 --- a/test/raven.test.js +++ b/test/raven.test.js @@ -873,6 +873,18 @@ describe('Raven (public API)', function() { wrapped(); assert.isTrue(spy.calledOnce); }); + it('should copy property when wrapping function', function() { + var func = function() {}; + func.test = true; + var wrapped = Raven.wrap(func); + assert.isTrue(wrapped.test); + }); + it('should not copy prototype property when wrapping function', function() { + var func = function() {}; + func.prototype.test = true; + var wrapped = Raven.wrap(func); + assert.isUndefined(new wrapped().test); + }); }); describe('.context', function() {