I write this:
$scope.localSearch = function () { var matches = 123; return matches; }; console.log($scope.localSearch); In the console:
How to return the variable itself and not the function?
I write this:
$scope.localSearch = function () { var matches = 123; return matches; }; console.log($scope.localSearch); In the console:
How to return the variable itself and not the function?
Or so
$scope.localSearch = function () { var matches = 123; return matches; }(); console.log($scope.localSearch); () at the end? It seems to be done at once, but how will it continue to behave? Now you can call everywhere without brackets $scope.localSearch . What is the other side of the coin? - borodatychUPD about what I'm saying, please comment, I am suddenly mistaken. - borodatychIt is possible so:
$scope.localSearch = function () { var matches = 123; return matches; }; $scope.myVar = $scope.localSearch(); console.log( $scope.myVar ); UPD
Use via function(){}() :
$scope.test = 0; $scope.localSearch = function () { return $scope.test; }(); $interval(function(){ console.log("EVERY 1 SEC: " + $scope.localSearch); },1000); $interval(function(){ $scope.test++; console.log("EVERY 3 SEC: " + $scope.test); console.log("EVERY 3 SEC: " + $scope.localSearch); },3000); If
localSearchshould depend on the$scope.testand primitive$scope.test, then it is better to abandon this method!
$scope.test would be an object and its fields changed — then there would be no difference — GrundySource: https://ru.stackoverflow.com/questions/512530/
All Articles
console.log($scope.localSearch());- Grundy$scope.localSearch- contains a link to the function with the body `var matches = 123; return matches;, что - бы вернуть значение нужно функцию запустить() ` - pepel_xD