84669 人学习
152542 人学习
20005 人学习
5487 人学习
7821 人学习
359900 人学习
3350 人学习
180660 人学习
48569 人学习
18603 人学习
40936 人学习
1549 人学习
1183 人学习
32909 人学习
http.createServer((req,res)=>{ res.write('hello world'); console.log(typeof res);// obj res.end(); });
如何 查看req和res的具体对象类型,这样可以去文档中看具体详细api.typeof打印出的是object,我希望打印出的是http.ServerResponse
怎么搞
打印函数的类信息:
function classof(obj){ if(typeof(obj)==="undefined")return "undefined"; if(obj===null)return "Null"; var res = Object.prototype.toString.call(obj).match(/^\[object\s(.*)\]$/)[1]; if(res==="Object"){ res = obj.constructor.name; if(typeof(res)!='string' || res.length==0){ if(obj instanceof jQuery)return "jQuery";// jQuery build stranges Objects if(obj instanceof Array)return "Array";// Array prototype is very sneaky return "Object"; } } return res; } // Example console.log(classof(new Date())); // => "Date"
打印函数的类信息: