Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ryanhanwu
Created June 4, 2012 07:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanhanwu/2866961 to your computer and use it in GitHub Desktop.
Save ryanhanwu/2866961 to your computer and use it in GitHub Desktop.
JavaScript Anti-Pattern
* 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