Last active
September 30, 2023 03:13
-
-
Save esatterwhite/ef696dd8532a46e5b2693af5a95c4c13 to your computer and use it in GitHub Desktop.
Classes stop being classes
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
'use strict'; | |
function typeOf( item ){ | |
if(item === null) { | |
return 'null'; | |
} else if(item === undefined) { | |
return 'undefined'; | |
} | |
if( typeof item.$family == 'function' ){ | |
return item.$family(); | |
} | |
if( !!item.$class ){ | |
return 'class'; | |
} | |
return ( Object.prototype.toString.call( item ) ).toLowerCase() | |
} | |
class Test extends Uint8ClampedArray{ | |
constructor(){ | |
super( 4 ); | |
} | |
$family(){ | |
return 'test'; | |
} | |
} | |
for( let idx = 0; idx < 1000; idx++ ){ | |
console.log( typeOf( new Test() ) ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment