function analyseScopeAndWatchers() { // fetch all elements with ng-scope class var scopeElements = Array.prototype.slice.apply(document.querySelectorAll(".ng-scope")); // map elements to scopes var scopes = scopeElements.map(function (element) { return angular.element(element).scope(); }); // filter duplicated scopes created by ng-view var scopesById = {}; var uniqueScopes = []; scopes.forEach(function (scope) { if (scopesById[scope.$id] === undefined) { scopesById[scope.$id] = scope; uniqueScopes.push(scope); } }); // map uniqueScopes to watchers var watchers = uniqueScopes.map(function (scope) { return scope.$$watchers; }).filter(function (watchers) { return watchers != null; }); // extract the count values var watchersCountValues = watchers.map(function (watcher) { return watcher.length; }); // sum up the length with reduce var watchersCount = watchersCountValues.reduce(function(a,b) { return a + b; }); return { watchers: watchers, watchersCount: watchersCount, uniqueScopes: uniqueScopes }; }