From d899be9ecbafec12083dada3e24e27b61f11fc35 Mon Sep 17 00:00:00 2001 From: Devin Ivy Date: Sun, 28 Feb 2021 14:01:21 -0500 Subject: [PATCH] Preserve own function props --- index.js | 2 ++ test/index.js | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/index.js b/index.js index fe27a71..6e15362 100644 --- a/index.js +++ b/index.js @@ -10,6 +10,8 @@ module.exports = function hookable(fn) { return fn.apply(this, [].slice.call(arguments)) } + Object.assign(hooked, fn) + hooked.hook = function (hook) { fn = wrap(fn, hook) return this diff --git a/test/index.js b/test/index.js index f5318d3..77df7bf 100644 --- a/test/index.js +++ b/test/index.js @@ -129,3 +129,24 @@ tape('check a thing, maybe return something different, else change result', func t.end() }) + +tape('preserve own properties', function (t) { + + var add = function (a, b) { + return a + b + }; + + add.operation = 'addition' + add.obj = {} + add.hook = null + + var h = Hoox(add) + + t.equal(h(2, 4), 6) + t.equal(h.operation, 'addition') + t.deepEqual(h.obj, {}) + t.ok(typeof h.hook === 'function') + + t.end() + +})