Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
  <head>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular.js"></script>
    <meta charset="utf-8">
    <title>JS Bin</title>
  </head>
  <body ng-app="app" ng-controller="MainCtrl as vm">
    <div>
      Just calling the function: {{vm.fn('Calling')}}
    </div>
    <div>
      Using the filter: {{'Filter' | invoke:vm.fn}}
    </div>
    
    <div>
      Run digests:
      <div ng-repeat="x in [1,2,3]" ng-mouseover="vm.xHovers[$index] = true">
        Hover over me {{$index}}
      </div>
    </div>
  </body>
</html>
 
console.clear();
const app = angular.module('app', []);
app.filter('invoke', function() {
  return invokeFilter;
  
  function invokeFilter(firstArg, fn, ...remainingArgs) {
    return fn(...[firstArg, ...remainingArgs]);
  }
});
app.controller('MainCtrl', function() {
  const vm = this;
  
  vm.calls = {};
  
  vm.fn = fn;
    
  function fn(input) {
    vm.calls[input] = angular.isDefined(vm.calls[input]) ? vm.calls[input] : 0;
    vm.calls[input]++;
    console.log(vm.calls);
    return input;
  }
});
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
kentcdoddspro
0viewers