JavaScript:The Class of an Object
function is(type, obj) { var clas = Object.prototype.toString.call(obj).slice(8, -1); return obj !== undefined && obj !== null && clas === type; }is('String', 'test'); // true is('String', new String('test')); // trueIn the above example, Object.prototype.toString gets called with the value of this being set to the object whose [] value should be retrieved.
页:
[1]