underscore的result
var object = {
cheese: 'crumpets',
stuff: function(){
return "nonsense";
}
};
//crumpets
_.result(object,'cheese');
//nonsense
_.result(object,'stuff');
看出:
//如果对象 object 中的属性 property 是函数, 则调用它, 否则, 返回它对应的value值。 _.result(object,property);
源码分析:
_.result = function(object,property){
//参数判断
if(object == null){
return void 0;
}
var value = object[property];
//判断是否是方法
return _.isFunction(value) ? value.call(object) : value;
};
212

被折叠的 条评论
为什么被折叠?



