Created
November 7, 2013 03:00
-
-
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.
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
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