Weird behavior for this piece of code:
I have some Angular controller:
.controller('View1Ctrl', ['$scope', 'CrawlServerExecutor', function ($scope, CrawlServerExecutor) {
$scope.results = [];
var showResults = function (results) {
results.forEach(function (result) {
$scope.results.push(result);
});
};
When writing it like this:
var showResults = function (results) {
results.forEach($scope.results.push);
};
I get this error:
Error: undefined is not an object for trying to access the push function, I looked $scope.results inside the debugger and the object was recognized as an array, but for some reason in this syntax it does not refer to it's push function. and I like this code better because it's more elegant.
Anyone has any idea why this happens?
Thanks
thiswill be correctly set) as inresults.forEach($scope.results.push.bind($scope.results));showResultsgets called repeatedly? Are the results aggregated, or replaced? And is the parameter (results) an array of array-like object?$scope.results = results;?