Object.prototype.toString.call(obj).slice(8,-1)

1.Object.prototype.toString()

This method returns a string that describes the data type of the object, as custom objects is not covered, it returns "[object type]", Here, type is the actual object type. When using this method of detection can be used Object.prototype.toString.call () or Object.prototype.toString.apply () for testing, such as

var toString = Object.prototype.toString;
toString.call(new Date);//[object Date]
toString.call(new String);//[object String]
toString.call(Math);//[object Math]
toString.call(undefined);//[object Undefined]
toString.call(null);//[object Null]

Thus, the lead Object.prototype.toString.call (obj) .slice (8, -1), such as

Object.prototype.toString.call('ESStudio balabala……');
//"[object String]"
Object.prototype.toString.call('ESStudio balabala……').slice(8,-1);
//"String"

slice (startIndex, endIndex), indexed from zero, where 8 represents the bit 8 (inclusive), taken starts (in this case representative of the position of the rear space) - 1 represents a penultimate taken (no), so just intercepted [object String] in String.

Knot.

 

Guess you like

Origin www.cnblogs.com/SallyShan/p/11530619.html