Last active
December 16, 2015 12:39
-
-
Save Cycymomo/5436142 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isMap(m) { //similarly for Set, WeakMap, WeakSet | |
try { | |
Map.prototype.size.call(m); | |
return true; | |
} catch () {return false} | |
} | |
function isDataView(d) { | |
try { | |
DataView.prototype.buffer.call(d); | |
return true; | |
} catch () {return false} | |
} | |
function isPromise(p) { | |
try { | |
Promise.prototype.then.call(p); | |
return true; | |
} catch () {return false} | |
} | |
function isTypedArray(a) { //any TypedArray instance | |
try { | |
Uin32Array.prototype.buffer.call(a); | |
return true; | |
catch () {return false} | |
function isUint8ArrayArray(a) { //for exmaple | |
try { | |
return Uin8Array.prototype[Symbol.toStringTag].call(a)==="Uint8Array"; ? true : false; | |
} catch () {return false} | |
} | |
function isDate(d) { //for exmaple | |
try { | |
Date.prototype.getDay.call(d); | |
return true; | |
} catch () {return false} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Object.prototype.getType = function() { | |
return typeof this; | |
}; | |
Object.prototype.getTypeStrict = function() { | |
"use strict"; | |
return typeof this; | |
}; | |
Object.prototype.getInstance = function() { | |
return 'instanceof String : ' + (this.valueOf() instanceof String) + ' / instanceof Object : ' + (this.valueOf() instanceof Object); | |
}; | |
Object.prototype.getInstanceStrict = function() { | |
"use strict"; | |
return 'instanceof String : ' + (this.valueOf() instanceof String) + ' / instanceof Object : ' + (this.valueOf() instanceof Object); | |
}; | |
console.log('Type (no strict) : ' + "".getType()); // object | |
console.log('Type (stric) : ' + "".getTypeStrict()); // string | |
console.log('Instance (no strict) : ' + "".getInstance()); // object | |
console.log('Instance (strict) : ' + "".getInstanceStrict()); // string |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment