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
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.