I thought, that it might be possible to extend regular console.log function to make it print the name of consolling variable.
Eg that what I do right now to understand wich variable is being printed:
for (var k in obj) {
console.log('obj[k].a', obj[k].a);
console.log('obj[k].b', obj[k].b);
console.log('obj[k].c', obj[k].c);
console.log('obj[k].d', obj[k].d);
console.log('-------------');
//I put the string first, and then the value - it's really usefull when I have to debug very long function with lots of cycles and variables. But it takes time typing all those console.log functions :(
}
Is it possible to extend wondow.console function or create an alias function that will not only be shorter, but also will typout the name of consolling variable?
Did you mean?
for (var k in obj) {
console.log('obj["'+k+'"]', obj[k]);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.