Implementing var_dump similar to php in javascript

The debugging function in the javascript language is pitiful, and if the object data returned by a third party is involved, the development level is increased. I thought that var_dump and print_r in php are simple and easy to use, which greatly facilitates the development work. I searched around on the Internet and finally found a similar method. Although it is not as tricky as my p, it saves a lot of money. effort. Some students may be so stubborn that "the three parties can't check the manual?" Well, this question is a good question. What if the paragraph you are looking for is missing from the manual, and if the manual is incomplete, it is found in the actual development. Manuals also have lag. Some students are stubborn to the point that "the three-party data interaction is not just json transmission." Well, this question is also reasonable. If the students have such questions, I suggest you to charge. Okay, not much more to say, on the code:

function var_dump(o){  
    var str = [];  
    var pre = '';  
    typeof o == 'function' && '';  
    typeof o == 'string' ? alert(o) : alert(each.call(o));  
    function each(o){  
        for (var p in this) {  
            typeof this[p] == 'object' && (pre += '[' + p + '].', each.call(this[p])) || str.push(pre + '[' + p + ']->[' + this[p] + '] /r/n')  
        }  
        return str.join('');  
    }  
}

author gj

Guess you like

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