From 4b9e7f4f30ffde0872bf86cfc0b9ee27013ab2b2 Mon Sep 17 00:00:00 2001 From: Bob Wallis Date: Wed, 2 Jan 2013 19:17:05 +0000 Subject: [PATCH 1/2] Adjust behaviour of eve.f to match eve --- eve.js | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/eve.js b/eve.js index c8eb5c4..9c3792c 100644 --- a/eve.js +++ b/eve.js @@ -183,24 +183,26 @@ * eve.f [ method ] ** - * Returns function that will fire given event with optional arguments. - * Arguments that will be passed to the result function will be also - * concated to the list of final arguments. - | el.onclick = eve.f("click", 1, 2); - | eve.on("click", function (a, b, c) { - | console.log(a, b, c); // 1, 2, [event object] - | }); + * Returns function that will fire event with given `name`, `scope` and optional arguments. + * Arguments that are be passed to the result function will also be concatenated to the list of final arguments. + | el.onclick = eve.f("click", 1, 2); + | eve.on("click", function (a, b, c) { + | console.log(a, b, c); // 1, 2, [event object] + | }); > Arguments - - event (string) event name - - varargs (…) and any other arguments - = (function) possible event handler function + ** + - name (string) name of the *event*, dot (`.`) or slash (`/`) separated + - scope (object) context for the event handlers + - varargs (...) the rest of arguments will be sent to event handlers + ** + = (function) possible event handler function \*/ - eve.f = function (event) { - var attrs = [].slice.call(arguments, 1); - return function () { - eve.apply(null, [event, null].concat(attrs).concat([].slice.call(arguments, 0))); - }; - }; + eve.f = function (name, scope) { + var fargs = [].slice.call(arguments, 0); + return function () { + eve.apply(null, fargs.concat([].slice.call(arguments, 0))); + }; + }; /*\ * eve.stop [ method ] From fcc472fc18f3e55e071b17524df37870867e28ce Mon Sep 17 00:00:00 2001 From: Bob Wallis Date: Wed, 2 Jan 2013 19:26:14 +0000 Subject: [PATCH 2/2] Force 'undefined' to be given as scope even if not passed. Prevent unexpected behaviour if passing additional arguments to the function returned by eve.f --- eve.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eve.js b/eve.js index 9c3792c..f8bc0de 100644 --- a/eve.js +++ b/eve.js @@ -198,7 +198,7 @@ = (function) possible event handler function \*/ eve.f = function (name, scope) { - var fargs = [].slice.call(arguments, 0); + var fargs = [name, scope].concat([].slice.call(arguments, 2)); return function () { eve.apply(null, fargs.concat([].slice.call(arguments, 0))); };