This library is an extension for Underscore which allows wrapping a conditional method before executing the main one, if true it calls the subsequent method.
- Prevent functions to be called unintentionally.
- underscore.js (>= 1.5.0)
var _ = require('underscore');
_.mixin(require('underscore.prefilter'));
var bark = function(sentence) {
console.log("woof " + sentence + "!");
};
bark = _.prefilter(bark, function(sentence) {
return !_.isNumber(sentence);
});
bark("woof"); // woof woof!
bark(123); // undefined
Copyright (c) 2013-2014 Mateus Maso. Released under an MIT license.