Last active
August 29, 2015 14:02
-
-
Save mrgenixus/ff3edfdbe29b1120204c to your computer and use it in GitHub Desktop.
jquerify or preprocess the context of a callback(curry the context)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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