<< 2010年1月25日 | 首页 | 2010年1月27日 >>

Javascript Best Practices

 

Introduction

This document is a list of best practices and preferred ways of developing javascript code, based on opinions and experience from many developers in the javascript community. Since this is a list of recommendations rather than a list of absolute rules, experienced developers may have slightly differing opinions from those expressed below.


Table Of Contents

  1. Always Use 'var'
  2. Feature-Detect Rather Than Browser-Detect
  3. Use Square Bracket Notation
  4. Avoid 'eval'
  5. Reference Forms and Form Elements Correctly
  6. Avoid 'with' Statements
  7. Use onclick In Anchors Instead Of javascript: Pseudo-Protocol
  8. Use The Unary + Operator To TypeConvert To Number
  9. Avoid document.all
  10. Don't Use HTML Comments In Script Blocks
  11. Avoid Cluttering The Global Namespace
  12. Avoid sync "Ajax" calls
  13. Use JSON
  14. Use Correct <script> Tags

阅读全文……

标签 :