Daily when the return value of the encapsulated function is undefined

ah I encountered a problem today, I wrote a public class


var utils = {
//实现将类数组转化为数组
 listToArray:function(likeAry){
 var ary = [];
 try{
 ary = Array.prototype.slice.call(likeAry);
 }
 catch(e) {
 for(var i = 0;i<likeAry.length;i++){ary[ary.length] = likeAry[i];}
 }
return ary;
},
//把JSON格式的字符串转换为JSON格式的对象
jsonParse:function(str){
    var val = null;
    try{
        val=JSON.parse(str);
    }catch(e){
        val=eval("("+str+")");
    }
}
}

It was like this at the time. When I called the jsonParse method, it returned undefined. I thought and thought, and finally found that there seemed to be no return value. . . . I really want to give myself two slaps. . .


var utils = {
//实现将类数组转化为数组
 listToArray:function(likeAry){
 var ary = [];
 try{
 ary = Array.prototype.slice.call(likeAry);
 }
 catch(e) {
 for(var i = 0;i<likeAry.length;i++){ary[ary.length] = likeAry[i];}
 }
return ary;
},
//把JSON格式的字符串转换为JSON格式的对象
jsonParse:function(str){
    var val = null;
    try{
        val=JSON.parse(str);
    }catch(e){
        val=eval("("+str+")");
    }
    return val;
}
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326259396&siteId=291194637