Created
June 4, 2012 07:33
-
-
Save ryanhanwu/2866961 to your computer and use it in GitHub Desktop.
JavaScript Anti-Pattern
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
* Polluting the global namespace by defining a large number of variables in the global context | |
* Passing strings rather than functions to either setTimeout or setInterval as this triggers the use of eval() internally. | |
* Modifying the Object class prototype (this is a particularly bad anti-pattern) | |
* Using JavaScript in an inline form as this is inflexible | |
* The use of document.write where native DOM alternatives such as document.createElement are more appropriate. document.write has been grossly misused over the years and has quite a few disadvantages including that if it's executed after the page has been loaded it can actually overwrite the page we're on, whilst document.createElement does not. We can see here for a live example of this in action. It also doesn't work with XHTML which is another reason opting for more DOM-friendly methods such as document.createElement is favorable. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment