Skip to content

Instantly share code, notes, and snippets.

@brigand
Created February 9, 2015 02:32
Show Gist options
  • Select an option

  • Save brigand/22edd5812be0c1158a00 to your computer and use it in GitHub Desktop.

Select an option

Save brigand/22edd5812be0c1158a00 to your computer and use it in GitHub Desktop.
jquery fn vs commonjs
// non-modular
jQuery.fn.limit = function(count){
return $(this).filter(function(index){ return index < count; });
};
// non-modular usage
$('sel').limit(3);
// modular
var $ = require('jquery');
var limit = function(count){
return $(this).filter(function(index){ return index < count; });
};
module.exports = Function.call.bind(limit);
// modular usage
var limit = require('./plugins/limit');
limit($('sel'), 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment