floydwch / angular-underscore

Underscore adapter for AngularJS
316 stars 86 forks source link

Sorry but... #5

Open ProLoser opened 11 years ago

ProLoser commented 11 years ago

You could just do:

myApp.filter('_', function(){
  return function() {
    var args = Array.prototype.slice.call(arguments, 0);
    var method = args.splice(1,1)[0];
    return _[method].apply(this, args);
  }
});
angular.forEach(_, function(method, name){
  // prefix all filters with '_' to prevent clobbering (such as $filter('filter') )
  myApp..filter('_'+name, function(){
    return method;
  });
});

Demo: http://plnkr.co/edit/Jq1Lg5v1GquxnqHe5hj2?p=preview

floydwch commented 11 years ago

Thank you for your advice, but not every underscore's method would be a proper filter, and some angular filter's use conventions could be merged with underscore, you could read the usage of filter in both angular and underscore, I have merged them together.