我可以使用構造函數屬性來檢測JavaScript中的類型嗎? 或者有什麼我應該知道的。我可以使用constructor.name來檢測JavaScript中的類型嗎
例如:var a = {}; a.constructor.name; //outputs Object
或var b = 1; b.constructor.name; //outputs Number
或var d = new Date(); d.constructor.name; //outputs Date not Object
或var f = new Function(); f.constructor.name; //outputs Function not Object
只有在使用它的參數arguments.constructor.name; //outputs Object like first example
我看到使用往往開發商:Object.prototype.toString.call([])
或
Object.prototype.toString.call({})
'constructor.name'在IE中不起作用。 – gruentee
@gruentee [引用需要] 在IE11中工作得很好 –