Skip to content

Instantly share code, notes, and snippets.

@animatedlew
Created November 7, 2013 03:00
Show Gist options
  • Save animatedlew/7348219 to your computer and use it in GitHub Desktop.
Save animatedlew/7348219 to your computer and use it in GitHub Desktop.
This is an example of functional programming using JavaScript's built-in filter, map, and forEach functions. Note that this isn't a fully functional style as there are side effects.
var selectAll = function() {
views.filter(function(view) {
if (view.$el.hasClass("active") !== toggle) {
return true;
}
}).map(function(view) {
return view.$el;
}).forEach(function($el) {
$el.toggleClass("active", toggle)
.find("input:checkbox")
.prop("checked", toggle);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment