Friday, April 18, 2014

Things that must be considered before writing JavaScript based application Or Using JavaScript in applications

Things like classes, methods, access modifier, Public / Private properties that must be considered before writing JavaScript based application to make it Optimised, Browser friendly, maintainable, reusable....

Client Side processing is very common in the applications that are in development phase. Almost all the applications are developed with the consideration of Cross Browser / Cross Platform support. This is a very common culture even new technologies like MVC , SharePoint, Mobile Apps, HTML5 relies heavily on client side processing using JavaScript and Jquery. There many JS patterns available in the market (most of them are open source or free to use and extend). but still we have to write requirement specific code for our application.

So we must consider How to write JS code in best way as there is no famous development tool for JS development. Following points must be considered before writing any JS based solution.

  • Do not Pollute the global namespace by defining a large number of variables in the global context.
  • Do not pass strings rather than functions to either setTimeout or setInterval as this triggers the use of eval() internally which is an extra call.
  • Never Modify the Object class prototype, this may lead you to get undesired output in the case that are left to handle and this is illogical also.
  • Don’t write JavaScript in an inline form as this is inflexible and can’t be reused on other pages
  • Do not ever use document.write where native DOM alternatives such as document.createElement are more appropriate. As 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.
  • Use the methods that works with XHTML which is another reason opting for more DOM-friendly methods such as document.createElement is favorable.

... List will continue with the articles of JS Design Patterns in other articles.


This comment has been removed by the author.

Post a Comment