代码检验注意点

函数中检验,控制台输出结果应在  return返回结果    之前,

【1】控制台输出结果应在  return返回结果之前

【2】return之后检验控制台输出为undefined

例:ItemCount.prototype.get_count = function(good){
var item_count=_.countBy(this.inputs,function(barcode){
        return barcode.split('-')? barcode:barcode.split('-');
    });
    for(good in item_count){
        if(_.indexOf(good,'-')!=-1){
            item_count[good.split('-')[0]]=good.split('-')[1];
            item_count[good]=undefined;
        }
    }
     【1】console.log(item_count)==>输出正常返回结果
    return item_count;===>返回{"ITEM000001":5,"ITEM000005":3,"ITEM000003":"2"}
     【2】console.log(item_count)==>输出undefined
   } 

猜你喜欢

转载自570109268.iteye.com/blog/2355375