underscore의 결과

1058 단어 underscoreresult

 
    result
 
   _.result(object,property)
 
 
   
  • 매개 변수object가function이면 실행합니다
  • 기타 상황은 직접 되돌아옵니다

  •  
    공식 사례:
     
     
    var object = {
    
          cheese:"crumpets",
    
          stuff:function(){
             
               return "nonsense";
    
          }
    
    };
    
    _.result(object,"cheese");   //"crumpets"
    
    
    _.result(object,"stuff");     //"nonsense"

     
     
    소스 코드 확인:
     
    /*
     * @name result
     * @param object
     * @param property
     * @info  _.isFunction
    
    */
    _.result = function(object,property){
    
            // null 
            if(object == null){
                   return null;
            }
    
            var value = object[property];
    
            // , call, key 
            return _.isFunction(value) ? value.call(object) : value;
    
    
    }

     
     

    좋은 웹페이지 즐겨찾기