Skip to content

Instantly share code, notes, and snippets.

@jsdbroughton
Created May 31, 2013 11:42
Show Gist options
  • Save jsdbroughton/5684446 to your computer and use it in GitHub Desktop.
Save jsdbroughton/5684446 to your computer and use it in GitHub Desktop.
jQuery var function to pass into a $(query).each() loop. In the stripped instance here, HTML5 data-* tags can control multiple events and types within one each call. "desk" here is a constructor with prototyped functions, but really the typeof test could be replaced with an eval on the value in the data-* attribute.
iconFunctions = function() {
$(this).click(function (e) {
var f = (e.target.attributes['data-function'] || {}).textContent;
if (typeof desk[f] === 'function') {
desk[f](e);
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment