Skip to content

Instantly share code, notes, and snippets.

@itzarty
Created July 11, 2022 12:35
Show Gist options
  • Select an option

  • Save itzarty/8cbccd740e3f56a5b3bc16f8353d18f6 to your computer and use it in GitHub Desktop.

Select an option

Save itzarty/8cbccd740e3f56a5b3bc16f8353d18f6 to your computer and use it in GitHub Desktop.
Object.prototype.switch = function( switchTo ) {
if( !switchTo ) return { };
if( !switchTo[this] && !switchTo.default ) return { };
if( !switchTo[this] && switchTo.default ) return switchTo.default;
return switchTo[this];
}
@itzarty
Copy link
Author

itzarty commented Jul 14, 2022

It turns out that this prototype in fact happens to be not so friendly with jQuery. Will post an updated version later.
PS: I'm not completely sure where the error occurs with jQuery as I would have to investigate the jQuery source code, however it seems that only in very specific scenarios this error does occur, a temporary patch for you out there experiencing the issue could be changing the type to which the prototype is assigned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment