0

The proxy function will not work, but a normal function is ok

What can i do to make it work

It's problably a scope issue, but how do I use "apply" or "call" in this context?

delegateEvents: function(){
          for (var key in this.events) {
            var methodName = this.events[key];
            var method     = this.proxy(this[methodName]);

            var match      = key.match(this.eventSplitter);
            var eventName  = match[1], selector = match[2];

            if (selector === '') {
              this.el.bind(eventName, method);
            } else {
                eventName == "click" && ( eventName = "tap click");
                console.log("selector",selector);
                console.log("eventName",eventName);
                var eel = $$(selector, $(this.el));
                Hammer(eel).on(eventName, method);
            }
          }
        }
      });

and a part of Hammer

Hammer.Instance.prototype = {
    /**
     * bind events to the instance
     * @param   {String}      gesture
     * @param   {Function}    handler
     * @returns {Hammer.Instance}
     */
    on: function onEvent(gesture, handler){
        var gestures = gesture.split(' ');
        for(var t=0; t<gestures.length; t++) {
            this.element.addEventListener(gestures[t], handler, false);
        }
        return this;
    },

proxy function

util = {
        proxy: function(fn, context, args){
            var argsArr = slice(arguments, 2); //curried args
            return function(){
                return fn.apply(context, argsArr.concat(slice(arguments)));
            };
        },

becomes part of the controller

result.proxy    = function(func){ return util.proxy(func, this); };
so, this.proxy == result.proxy and the context is already set to this

thanks if anyone knows this

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
Richard
  • 4,516
  • 11
  • 60
  • 87
  • So `this` is `util`, and you want to bind the `method` to what context? – Bergi Aug 05 '13 at 13:52
  • the Spine controller, but I thought the proxy was already doing that. Util is just a separate object with some helper functions. Edited the question to clarify. – Richard Aug 05 '13 at 14:43
  • Ah OK. That looks like it would work already, doesn't it? – Bergi Aug 05 '13 at 14:45
  • no it does not do anything, well very strangely one method does work, no idea why http://www.hotelbel.nl – Richard Aug 05 '13 at 14:47
  • @Richard, can you post a jsfiddle? – cam Aug 05 '13 at 17:15
  • I would not know what to put in the fiddle, problably easyer to get to the site and look in the console. I did put a couple console.logs on the delegate method. It seems the only time it did work was when the selector had no child elements. The rest of the selectors return a structure. I am investigating why this is. – Richard Aug 05 '13 at 17:25

1 Answers1

0

The problem was that the Minified library returned a selector that the Hammer library could not work with.

Well, that was my first assumption

It was actually the fact that I was using one type of selector for two different functions, the "$" version, wich returns the Minified object, but Hammer just needs the node and therefore needs the "$$" version.

Richard
  • 4,516
  • 11
  • 60
  • 87