Skip to content

Instantly share code, notes, and snippets.

@mrgenixus
Last active August 29, 2015 14:02
Show Gist options
  • Select an option

  • Save mrgenixus/ff3edfdbe29b1120204c to your computer and use it in GitHub Desktop.

Select an option

Save mrgenixus/ff3edfdbe29b1120204c to your computer and use it in GitHub Desktop.
jquerify or preprocess the context of a callback(curry the context)
function pre(process, func){
return function(){
return func.apply(process(this), arguments);
}
}
function jquerify (func){ return pre($, func); }
$('div').map(jquerify(function(v, i){
return this.attr('id');
}))
$('div').map(pre(_, function(){
return this.chain().keys().include('data-toggle') == true;
}))
$('div').map(pre(_, function(){
return this.filter(function(value, key){
return value && /^on/.test(key)
});
}));
/*
* It turns out this is a bad idea:
*/
var myeach = $.each
$.each = function(set, callback){
myeach(set, function(){
callback.apply($(this), arguments);
}
}
/*
* For some reason, when an even is triggered, it calls' the handler on each of them,
* but if the each returns a jQuery, it seems to try to iterate over it again -- Maximum call stack size exceeded
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment