Created
November 9, 2012 21:45
-
-
Save munro/4048461 to your computer and use it in GitHub Desktop.
Strengthen JS Types
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
/** | |
* STRENGTH! | |
*/ | |
Object.prototype.toString = Array.prototype.toString = undefined; | |
/** | |
* Now operators will throw an exception when attempting | |
* to convert objects & arrays to a string! | |
*/ | |
[] + {}; // nope | |
1 - []; // nope | |
[] * 123; // nope | |
'foo' >> {}; // nope | |
'bar' << {}; // nope | |
/** | |
* Wait, wait... why the ()? Well... JS has this useless block syntax. | |
* So {} is an empty block statement, which means without () JS would see: | |
* {}; // Cool statement! | |
* / {}; // Wat? You're not dividing by anything! | |
*/ | |
({} / {}); // nope |
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
[] + {} === '[object Object]'; // wat | |
1 - [] === 1; // wat | |
[] * 123 === 0; // wat | |
({} / {}) === '[object Object][object Object]'; // wat | |
'foo' >> {} === 0; // wat | |
'bar' >> {} === 0; // wat | |
isNaN({} / {}) === true; // wat... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment