From 992df08c900e6340a0e5b640f4fa9154824b801b Mon Sep 17 00:00:00 2001 From: ketmar Date: Tue, 1 Sep 2015 10:41:50 +0000 Subject: [PATCH] better `tieto()` FossilOrigin-Name: 2f7af8cc7d45ac86040058160dc3d36b730b3e331d038a61761f223c2bf8f152 --- main/init.js | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/main/init.js b/main/init.js index 9407e9f..9abe67d 100644 --- a/main/init.js +++ b/main/init.js @@ -79,23 +79,13 @@ default: throw new Error("`method` should be function or method name"); } - let me = obj; - let rest = Array.prototype.splice.call(arguments, 2, arguments.length); - /* - let stk; - try { throw new Error("!"); } catch (e) { - //print("TIETO!\n"+e.stack); - stk = e.stack.split("\n")[1]; - } - */ - return function () { - //print(stk); - // `rest` is reused for each invocation, so copy it, and append new arguments to copy - let args = Array.prototype.slice.call(rest); - Array.prototype.push.apply(args, arguments); - return mt.apply(me, args); - }; + // hack: replace first array item; avoiding extra arrays + let rest = Array.prototype.splice.call(arguments, 1, arguments.length); + rest[0] = obj; + // now use `bind` + return mt.bind.apply(mt, rest); } + const sb_tieto = tieto(gsbox, tieto); Object.defineProperty(gsbox, "tieto", {get: function () sb_tieto}); -- 2.11.4.GIT