주니봉
  • angular.noop()
    2020년 12월 30일 10시 22분 02초에 업로드 된 글입니다.
    작성자: 봉주니

    angular.noop 은 아무런 작업도 수행하지 않는 함수이며 아무것도 수행하지 않을 함수 인수를 제공해야 할 경우 angular.noop 을 전달합니다.

    angular.noop ()

    angular.noop 의 일반적인 사용은 함수에 빈 콜백을 제공하여 함수가 아닌 다른 것이 전달 될 때 오류를 던질 수 있습니다.

     

    예:

    $scope.onSomeChange = function(model, callback) {
    
         updateTheModel(model);
    
         if (angular.isFunction(callback)) {
    
              callback();
    
         } else {
    
              throw new Error("error: callback is not a function!");
    
         }
    
    };
    
    
    
    $scope.onSomeChange(42, function() {console.log("hello callback")});
    
    // will update the model and print 'hello callback'
    
    $scope.onSomeChange(42, angular.noop); // will update the model

     

    추가 예제 :

    angular.noop() // undefined

    angular.isFunction(angular.noop) // true

     

    발췌 : riptutorial.com/ko/angularjs/example/12274/angular-noop

    반응형
    댓글