Skip to content

Instantly share code, notes, and snippets.

@esatterwhite
Last active September 30, 2023 03:13
Show Gist options
  • Save esatterwhite/ef696dd8532a46e5b2693af5a95c4c13 to your computer and use it in GitHub Desktop.
Save esatterwhite/ef696dd8532a46e5b2693af5a95c4c13 to your computer and use it in GitHub Desktop.
Classes stop being classes
'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