전체 페이지뷰

2013년 11월 10일 일요일

javascript patterns essentiers

  1. from javascript patterns 
    JSLint
    JavaScript is an interpreted language with no static compile-time checks. So it’s possible to deploy a broken program with a simple typing mistake without realizing it. This is where JSLint helps.
    JSLint (http://jslint.com) is a JavaScript code quality tool created by Douglas Crockford that inspects your code and warns about potential problems. It’s highly recommended that you run your code through JSLint. The tool “will hurt your feelings” as its creator warns, but only in the beginning. You can quickly learn from your mistakes and adopt the essential habits of a professional JavaScript programmer. Having no JSLint error in your code also helps you be more confident in the code, knowing that you didn’t make a simple omission or syntax error in a hurry.
     We often use the method log(), which prints all the parameters passed to it, and some- times dir(), which enumerates the object passed to it and prints all properties. Here’s an example usage:
    console.log("test", 1, {}, [1,2,3]); console.dir({one: 1, two: {three: 3}});
    When you type in the console, you don’t have to use console.log(); you can simply omit it. To avoid clutter, some code snippets skip it, too, and assume you’re testing the code in the console:
    window.name === window['name']; // true
    This is as if we used the following:
    console.log(window.name === window['name']); and it printed true in the console. 
    Writing Maintainable Code
    • Time to relearn and understand the problem
    • Time to understand the code that is supposed to solve the problem 

      Maintainable code means code that:
      • Is readable
      • Is consistent
      • Is predictable
      • Looks as if it was written by the same person
      • Is documented 

댓글 없음:

댓글 쓰기