Created
August 3, 2020 17:04
-
-
Save ahuggins-nhs/e61ccb900b5eb1ef3c57233a5c5e0fce to your computer and use it in GitHub Desktop.
This file contains 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 typeOf (val) { | |
let typeDef = typeof val | |
console.log('init:', typeDef) | |
if (typeDef === 'object' || typeDef === 'function') { | |
console.log('obj/func:', typeDef) | |
typeDef = Object.prototype.toString.call(val) | |
typeDef = typeDef.substring(8, typeDef.length - 1) | |
} | |
if (typeDef === 'Object' || typeDef === 'Array') { | |
console.log('Obj/Arr:', typeDef) | |
typeDef = Object.getPrototypeOf(val).constructor.name | |
} | |
return typeDef | |
} | |
class Klass extends Array { constructor() { super() } } | |
class Qlass extends Klass { constructor() { super() } } | |
class Strang extends String { constructor() { super() } } | |
console.log(typeOf(null)) | |
console.log(typeOf(async function () {})) | |
console.log(typeOf(function () {})) | |
console.log(typeOf(new Klass())) | |
console.log(typeOf(new Qlass())) | |
console.log(typeOf(new Strang())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment