Skip to content

borislavib/javascript

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 

Repository files navigation

Original Repository: airbnb/javascript

Airbnb JavaScript Style Guide() {

Π Π°Π·ΡƒΠΌΠ΅Π½ ΠΏΠΎΠ΄Ρ…ΠΎΠ΄ Π·Π° писанС Π½Π° JavaScript

  1. Π’ΠΈΠΏΠΎΠ²Π΅
  2. ΠžΠ±Π΅ΠΊΡ‚ΠΈ
  3. Масиви
  4. НизовС
  5. Π€ΡƒΠ½ΠΊΡ†ΠΈΠΈ
  6. ΠŸΠΎΠ»Π΅Ρ‚Π°
  7. ΠŸΡ€ΠΎΠΌΠ΅Π½Π»ΠΈΠ²ΠΈ
  8. Π”Π΅ΠΊΠ»Π°Ρ€ΠΈΡ€Π°Π½Π΅ ΠΈ ΠΈΠ·ΠΏΠΎΠ»Π·Π²Π°Π½Π΅ Π½Π° ΠΏΡ€ΠΎΠΌΠ΅Π½Π»ΠΈΠ²ΠΈ
  9. Условни ΠΈΠ·Ρ€Π°Π·ΠΈ ΠΈ равСнства
  10. Π‘Π»ΠΎΠΊΠΎΠ²Π΅
  11. ΠšΠΎΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈ
  12. ΠŸΡ€Π°Π·Π½ΠΈ ΠΏΠΎΠ»Π΅Ρ‚Π°
  13. Π—Π°ΠΏΠ΅Ρ‚Π°ΠΈ
  14. Π’ΠΎΡ‡ΠΊΠ° ΠΈ запСтая
  15. ΠŸΡ€Π΅ΠΎΠ±Ρ€Π°Π·ΡƒΠ²Π°Π½Π΅ Π½Π° Ρ‚ΠΈΠΏΠΎΠ²Π΅
  16. НаимСнуванС ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠΈ
  17. Π”ΠΎΡΡ‚ΡŠΠΏΠ²Π°Π½Π΅
  18. ΠšΠΎΠ½ΡΡ‚Ρ€ΡƒΠΊΡ‚ΠΎΡ€ΠΈ
  19. Π‘ΡŠΠ±ΠΈΡ‚ΠΈΡ
  20. ΠœΠΎΠ΄ΡƒΠ»ΠΈ
  21. jQuery
  22. ES5 Π‘ΡŠΠ²ΠΌΠ΅ΡΡ‚ΠΈΠΌΠΎΡΡ‚
  23. ВСстванС
  24. ИзпълСниС
  25. РСсурси
  26. КъдС сС ΠΈΠ·ΠΏΠΎΠ»Π·Π²Π°Ρ‚ Ρ‚Π΅Π·ΠΈ ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠΈ
  27. ΠŸΡ€Π΅Π²ΠΎΠ΄
  28. JavaScript стилов ΠΏΡŠΡ‚Π΅Π²ΠΎΠ΄ΠΈΡ‚Π΅Π»
  29. Π‘ΡŠΡ‚Ρ€ΡƒΠ΄Π½ΠΈΡ†ΠΈ
  30. Π›ΠΈΡ†Π΅Π½Π·
  • ΠŸΡ€ΠΈΠΌΠΈΡ‚ΠΈΠ²Π½ΠΈ: ΠšΠΎΠ³Π°Ρ‚ΠΎ Π΄ΠΎΡΡ‚ΡŠΠΏΠ²Π°Ρ‚Π΅ ΠΏΡ€ΠΈΠΌΠΈΡ‚ΠΈΠ²Π΅Π½ Ρ‚ΠΈΠΏ сС Ρ€Π°Π±ΠΎΡ‚ΠΈ Π΄ΠΈΡ€Π΅ΠΊΡ‚Π½ΠΎ със Π½Π΅Π³ΠΎΠ²Π°Ρ‚Π° стойност.

    • string
    • number
    • boolean
    • null
    • undefined
    var foo = 1,
        bar = foo;
    
    bar = 9;
    
    console.log(foo, bar); // => 1, 9
  • Π‘ΡŠΡΡ‚Π°Π²Π½ΠΈ: ΠšΠΎΠ³Π°Ρ‚ΠΎ Π΄ΠΎΡΡ‚ΡŠΠΏΠ²Π°Ρ‚Π΅ комплСксСн Ρ‚ΠΈΠΏ Π΄Π°Π½Π½ΠΈ сС Ρ€Π°Π±ΠΎΡ‚ΠΈ с рСфСрСнция Π½Π° стойността ΠΈ.

    • object
    • array
    • function
    var foo = [1, 2],
        bar = foo;
    
    bar[0] = 9;
    
    console.log(foo[0], bar[0]); // => 9, 9

    [⬆]

  • Π˜Π·ΠΏΠΎΠ»Π·Π²Π°ΠΉΡ‚Π΅ втория Π²Π°Ρ€ΠΈΠ°Π½Ρ‚ Π·Π° създаванС Π½Π° ΠΎΠ±Π΅ΠΊΡ‚.

    // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
    var item = new Object();
    
    // Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
    var item = {};
  • НС ΠΈΠ·ΠΏΠΎΠ»Π·Π²Π°ΠΉΡ‚Π΅ Π·Π°ΠΏΠ°Π·Π΅Π½ΠΈ Π΄ΡƒΠΌΠΈ Π·Π° Π΄Π΅ΠΊΠ»Π°Ρ€ΠΈΡ€Π°Π½Π΅ Π½Π° ΠΏΡ€ΠΎΠΌΠ΅Π½Π»ΠΈΠ²ΠΈ. Π’Π΅Π·ΠΈ ΠΏΡ€ΠΎΠΌΠ΅Π½Π»ΠΈΠ²ΠΈ няма Π΄Π° работят Π½Π° IE8. ΠŸΠΎΠ²Π΅Ρ‡Π΅

    // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
    var superman = {
      default: { clark: 'kent' },
      private: true
    };
    
    // Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
    var superman = {
      defaults: { clark: 'kent' },
      hidden: true
    };
  • Π˜Π·ΠΏΠΎΠ»Π·Π²Π°ΠΉΡ‚Π΅ смислСни синоними Π½Π° мястото Π½Π° Π·Π°ΠΏΠ°Π·Π΅Π½ΠΈ Π΄ΡƒΠΌΠΈ.

    // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
    var superman = {
      class: 'alien'
    };
    
    // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
    var superman = {
      klass: 'alien'
    };
    
    // Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
    var superman = {
      type: 'alien'
    };

    [⬆]

  • Π˜Π·ΠΏΠΎΠ»Π·Π²Π°ΠΉΡ‚Π΅ Π²Π°Ρ€ΠΈΠ°Π½Ρ‚Π° със скобитС Π·Π° създаванС Π½Π° масив

    // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
    var items = new Array();
    
    // Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
    var items = [];
  • Ако Π½Π΅ Π·Π½Π°Π΅Ρ‚Π΅ Π΄ΡŠΠ»ΠΆΠΈΠ½Π°Ρ‚Π° Π½Π° масив, ΠΈΠ·ΠΏΠΎΠ»Π·Π²Π°ΠΉΡ‚Π΅ Array#push.

    var someStack = [];
    
    
    // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
    someStack[someStack.length] = 'abracadabra';
    
    // Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
    someStack.push('abracadabra');
  • Ако ΠΈΠΌΠ°Ρ‚Π΅ Π½ΡƒΠΆΠ΄Π° Π΄Π° ΠΊΠΎΠΏΠΈΡ€Π°Ρ‚Π΅ масив ΠΈΠ·ΠΏΠΎΠ»Π·Π²Π°ΠΉΡ‚Π΅ Array#slice. jsPerf

    var len = items.length,
        itemsCopy = [],
        i;
    
    // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
    for (i = 0; i < len; i++) {
      itemsCopy[i] = items[i];
    }
    
    // Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
    itemsCopy = items.slice();
  • Π”Π° ΠΊΠΎΠ½Π²Π΅Ρ€Ρ‚ΠΈΡ€Π°Ρ‚Π΅ ΠΏΠΎΠ΄ΠΎΠ±Π΅Π½ Π½Π° масив ΠΎΠ±Π΅ΠΊΡ‚ към масив, ΠΈΠ·ΠΏΠΎΠ»Π·Π²Π°ΠΉΡ‚Π΅ Array#slice.

    function trigger() {
      var args = Array.prototype.slice.call(arguments);
      ...
    }

    [⬆]

  • Π˜Π·ΠΏΠΎΠ»Π·Π²Π°ΠΉΡ‚Π΅ Π΅Π΄ΠΈΠ½ΠΈΡ‡Π½ΠΈ ΠΊΠ°Π²ΠΈΡ‡ΠΊΠΈ '' Π·Π° НизовС.

    // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
    var name = "Bob Parr";
    
    // Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
    var name = 'Bob Parr';
    
    // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
    var fullName = "Bob " + this.lastName;
    
    // Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
    var fullName = 'Bob ' + this.lastName;
  • НизовС, ΠΏΠΎ-дълги ΠΎΡ‚ 80 символа трябва Π΄Π° сС Π½Π°ΠΏΠΈΡˆΠ°Ρ‚ Π½Π° няколко Ρ€Π΅Π΄Π°, ΠΊΠ°Ρ‚ΠΎ сС ΠΈΠ·ΠΏΠΎΠ»Π·Π²Π° конкатСнация.

  • Π—Π°Π±Π΅Π»Π΅ΠΆΠΊΠ°: Ако сС ΠΈΠ·ΠΏΠΎΠ»Π·Π²Π°Ρ‚ Π½Π΅ΠΏΡ€Π°Π²ΠΈΠ»Π½ΠΎ, . jsPerf & s

    // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
    var errorMessage = 'This is a super long error that was thrown because of Batman. When you stop to think about how Batman had anything to do with this, you would get nowhere fast.';
    
    // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
    var errorMessage = 'This is a super long error that \
    was thrown because of Batman. \
    When you stop to think about \
    how Batman had anything to do \
    with this, you would get nowhere \
    fast.';
    
    
    // Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
    var errorMessage = 'This is a super long error that ' +
      'was thrown because of Batman.' +
      'When you stop to think about ' +
      'how Batman had anything to do ' +
      'with this, you would get nowhere ' +
      'fast.';
  • ΠšΠΎΠ³Π°Ρ‚ΠΎ искатС Π΄Π° Π½Π°ΠΏΡ€Π°Π²ΠΈΡ‚Π΅ Π½ΠΈΠ·, ΠΈΠ·ΠΏΠΎΠ»Π·Π²Π°ΠΉΡ‚Π΅ Array#join вмСсто конкатСнация. jsPerf.

    var items,
        messages,
        length,
        i;
    
    messages = [{
        state: 'success',
        message: 'This one worked.'
    },{
        state: 'success',
        message: 'This one worked as well.'
    },{
        state: 'error',
        message: 'This one did not work.'
    }];
    
    length = messages.length;
    
    // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
    function inbox(messages) {
      items = '<ul>';
    
      for (i = 0; i < length; i++) {
        items += '<li>' + messages[i].message + '</li>';
      }
    
      return items + '</ul>';
    }
    
    // Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
    function inbox(messages) {
      items = [];
    
      for (i = 0; i < length; i++) {
        items[i] = messages[i].message;
      }
    
      return '<ul><li>' + items.join('</li><li>') + '</li></ul>';
    }

    [⬆]

  • Π€ΡƒΠ½ΠΊΡ†ΠΈΠΈ-ΠΈΠ·Ρ€Π°Π·ΠΈ:

    // Анонимни Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΈ ΠΈΠ·Ρ€Π°Π·ΠΈ
    var anonymous = function() {
      return true;
    };
    
    // Π˜ΠΌΠ΅Π½ΡƒΠ²Π°Π½ΠΈΠ΅ Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΈ ΠΈΠ·Ρ€Π°Π·ΠΈ
    var named = function named() {
      return true;
    };
    
    // ΠœΠΎΠΌΠ΅Π½Ρ‚Π°Π»Π½ΠΎ изпълнСни Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΈ-ΠΈΠ·Ρ€Π°Π·ΠΈ (IIFE)
    (function() {
      console.log('Welcome to the Internet. Please follow me.');
    })();
  • Никога Π½Π΅ Π΄Π΅ΠΊΠ»Π°Ρ€ΠΈΡ€Π°ΠΉΡ‚Π΅ функция Π² Π½Π΅Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΎΠ½Π΅Π»Π΅Π½ Π±Π»ΠΎΠΊ (if, while, etc). Π”Π°ΠΉΡ‚Π΅ ΠΈ стойност ΠΈ Π½Π° ΠΏΡ€ΠΎΠΌΠ΅Π½Π»ΠΈΠ²Π° вмСсто Ρ‚ΠΎΠ²Π°. Π‘Ρ€Π°ΡƒΠ·ΡŠΡ€ΠΈΡ‚Π΅ Ρ‰Π΅ Π΄Π°Π΄Π°Ρ‚ Ρ‚ΠΎΠ²Π°, Π½ΠΎ Ρ‰Π΅ Π³ΠΎ ΠΈΠ½Ρ‚Π΅Ρ€ΠΏΡ€Π΅Ρ‚ΠΈΡ€Π°Ρ‚ Ρ€Π°Π·Π»ΠΈΡ‡Π½ΠΎ, ΠΊΠΎΠ΅Ρ‚ΠΎ Π½Π΅ Π΅ Π½ΠΈΠΊΠ°ΠΊ Π΄ΠΎΠ±Ρ€Π΅.

  • Π—Π°Π±Π΅Π»Π΅ΠΆΠΊΠ°: ECMA-262 Π΄Π΅Ρ„ΠΈΠ½ΠΈΡ€Π° block ΠΊΠ°Ρ‚ΠΎ лист с Π΄Π΅ΠΊΠ»Π°Ρ€Π°Ρ†ΠΈΠΈ/Ρ‚Π²ΡŠΡ€Π΄Π΅Π½ΠΈΡ. Π”Π΅ΠΊΠ»Π°Ρ€ΠΈΡ€Π°Π½Π΅Ρ‚ΠΎ Π½Π° фунция Π½Π΅ Π΅ Ρ‚Π²ΡŠΡ€Π΄Π΅Π½ΠΈΠ΅. Read ECMA-262's note on this issue.

    // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
    if (currentUser) {
      function test() {
        console.log('Nope.');
      }
    }
    
    // Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
    var test;
    if (currentUser) {
      test = function test() {
        console.log('Yup.');
      };
    }
  • Никога Π½Π΅ Π½Π°ΠΈΠΌΠ΅Π½ΠΎΠ²Π°ΠΉΡ‚Π΅ ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚ΡŠΡ€ arguments, Ρ‚ΠΎΠ²Π° Ρ‰Π΅ Π²Π·Π΅ΠΌΠ΅ Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅Ρ‚ΠΎ Π½Π° arguments-ΠΎΠ±Π΅ΠΊΡ‚Π°, ΠΊΠΎΠΉΡ‚ΠΎ Π΅ Π΄Π΅ΠΊΠ»Π°Ρ€ΠΈΡ€Π°Π½ ΠΏΠΎ ΠΏΠΎΠ΄Ρ€Π°Π·Π±ΠΈΡ€Π°Π½Π΅ във всСки скоуп.

    // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
    function nope(name, options, arguments) {
      // ...stuff...
    }
    
    // Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
    function yup(name, options, args) {
      // ...stuff...
    }

    [⬆]

  • Π˜Π·ΠΏΠΎΠ»Π·Π²Π°ΠΉΡ‚Π΅ '.' Π·Π° Π΄ΠΎΡΡ‚ΡŠΠΏΠ²Π°Π½Π΅ Π½Π° ΠΏΠΎΠ»Π΅Ρ‚Π°.

    var luke = {
      jedi: true,
      age: 28
    };
    
    // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
    var isJedi = luke['jedi'];
    
    // Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
    var isJedi = luke.jedi;
  • Π˜Π·ΠΏΠΎΠ»Π·Π²Π°ΠΉΡ‚Π΅ [] ΠΊΠΎΠ³Π°Ρ‚ΠΎ Π΄ΠΎΡΡ‚ΡŠΠΏΠ²Π°Ρ‚Π΅ ΠΏΠΎΠ»Π΅Ρ‚Π° с ΠΏΡ€ΠΎΠΌΠ΅Π½Π»ΠΈΠ²Π°.

    var luke = {
      jedi: true,
      age: 28
    };
    
    function getProp(prop) {
      return luke[prop];
    }
    
    var isJedi = getProp('jedi');

    [⬆]

  • Π’ΠΈΠ½Π°Π³ΠΈ ΠΈΠ·ΠΏΠΎΠ»Π·Π²Π°ΠΉΡ‚Π΅ var Π·Π° Π΄Π΅ΠΊΠ»Π°Ρ€ΠΈΡ€Π°Π½Π΅ Π½Π° ΠΏΡ€ΠΎΠΌΠ΅Π½Π»ΠΈΠ²ΠΈ. Π’ ΠΏΡ€ΠΎΡ‚ΠΈΠ²Π΅Π½ случай сС Π΄Π΅ΠΊΠ»Π°Ρ€ΠΈΡ€Π°Ρ‚ Π³Π»ΠΎΠ±Π°Π»Π½ΠΈ ΠΏΡ€ΠΎΠΌΠ΅Π½Π»ΠΈΠ²ΠΈ. НиС искамС Π΄Π° Π½Π΅ 'Π·Π°ΠΌΡŠΡ€ΡΡΠ²Π°Π½Π΅' Π³Π»ΠΎΠ±Π°Π»Π½ΠΎΡ‚ΠΎ пространство с тях. 'ΠšΠ°ΠΏΠΈΡ‚Π°Π½ ΠΏΠ»Π°Π½Π΅Ρ‚Π° Π½ΠΈ ΠΏΡ€Π΅Π΄ΡƒΠΏΡ€Π΅Π΄ΠΈ Π·Π° тях'.

    // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
    superPower = new SuperPower();
    
    // Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
    var superPower = new SuperPower();
  • Π˜Π·ΠΏΠΎΠ»Π·Π²Π°ΠΉΡ‚Π΅ Π΅Π΄Π½Π° var дСкларация Π·Π° ΠΌΠ½ΠΎΠ³ΠΎ ΠΏΡ€ΠΎΠΌΠ΅Π½Π»ΠΈΠ²ΠΈ ΠΈ Π΄Π΅ΠΊΠ»Π°Ρ€ΠΈΡ€Π°ΠΉΡ‚Π΅ всяка ΠΏΡ€ΠΎΠΌΠ΅Π½Π»ΠΈΠ²Π° Π½Π° Π½ΠΎΠ² Ρ€Π΅Π΄.

    // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
    var items = getItems();
    var goSportsTeam = true;
    var dragonball = 'z';
    
    // Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
    var items = getItems(),
        goSportsTeam = true,
        dragonball = 'z';
  • Π”Π΅ΠΊΠ»Π°Ρ€ΠΈΡ€Π°ΠΉΡ‚Π΅ ΠΏΡ€ΠΎΠΌΠ΅Π½Π»ΠΈΠ²ΠΈ, Π½Π΅ΠΏΡ€ΠΎΠ΄ΠΎΠ±ΠΈΠ»ΠΈ стойност послСдни. Π’ΠΎΠ²Π° Π΅ ΠΏΠΎΠ»Π΅Π·Π½ΠΎ, ΠΊΠΎΠ³Π°Ρ‚ΠΎ ΠΏΠΎ-късно сС Π½ΡƒΠΆΠ΄Π°Π΅Ρ‚Π΅ ΠΎΡ‚ ΠΏΡ€ΠΎΠΌΠ΅Π½Π»ΠΈΠ²Π° зависСща ΠΎΡ‚ някоя ΠΎΡ‚ ΠΏΡ€Π΅Π΄Ρ…ΠΎΠ΄Π½ΠΎ Π΄Π΅Ρ„ΠΈΠ½ΠΈΡ€Π°Π½ΠΈΡ‚Π΅ ΠΏΡ€ΠΎΠΌΠ΅Π½Π»ΠΈΠ²ΠΈ.

    // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
    var i, len, dragonball,
        items = getItems(),
        goSportsTeam = true;
    
    // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
    var i, items = getItems(),
        dragonball,
        goSportsTeam = true,
        len;
    
    // Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
    var items = getItems(),
        goSportsTeam = true,
        dragonball,
        length,
        i;
  • Π‘Π»Π°Π³Π°ΠΉΡ‚Π΅ ΠΏΡ€ΠΎΠΌΠ΅Π½Π»ΠΈΠ²ΠΈΡ‚Π΅ Π²ΠΈΠ½Π°Π³ΠΈ Π² Π½Π°Ρ‡Π°Π»ΠΎΡ‚ΠΎ Π½Π° скоупа ΠΈΠΌ. Π’ΠΎΠ²Π° ΠΏΠΎΠΌΠ°Π³Π° Π΄Π° сС ΠΈΠ·Π±Π΅Π³Π½Π°Ρ‚ ΠΏΡ€ΠΎΠ±Π»Π΅ΠΌΠΈ с Π΄Π΅ΠΊΠ»Π°Ρ€Π°Ρ†ΠΈΠΈ ΠΈ Π½Π΅ΠΏΡ€Π°Π²ΠΎΠΌΠ΅Ρ€Π½ΠΎ ΠΈΠ·Π²ΠΈΠΊΠ²Π°Π½Π΅ Π½Π° Π½Π΅Π΄Π΅Ρ„ΠΈΠ½ΠΈΡ€Π°Π½ΠΈ ΠΏΡ€ΠΎΠΌΠ΅Π½Π»ΠΈΠ²ΠΈ.

    // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
    function() {
      test();
      console.log('doing stuff..');
    
      //..Π΄Ρ€ΡƒΠ³ΠΈ..
    
      var name = getName();
    
      if (name === 'test') {
        return false;
      }
    
      return name;
    }
    
    // Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
    function() {
      var name = getName();
    
      test();
      console.log('doing stuff..');
    
      //..other stuff..
    
      if (name === 'test') {
        return false;
      }
    
      return name;
    }
    
    // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
    function() {
      var name = getName();
    
      if (!arguments.length) {
        return false;
      }
    
      return true;
    }
    
    // Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
    function() {
      if (!arguments.length) {
        return false;
      }
    
      var name = getName();
    
      return true;
    }

    [⬆]

  • ДСкларацията Π½Π° ΠΏΡ€ΠΎΠΌΠ΅Π½Π»ΠΈΠ²ΠΈ сС поставя Π² Π½Π°Ρ‡Π°Π»ΠΎΡ‚ΠΎ Π½Π° функция ΠΈΠ»ΠΈ ΠΎΠ±Π΅ΠΊΡ‚, тяхното ΠΈΠ·ΠΏΠΎΠ·Π»Π²Π°Π½Π΅ става ΠΏΠΎ-Π½Π°Π΄ΠΎΠ»Ρƒ.

    // Π’ΠΎΠ²Π° няма Π΄Π° Ρ€Π°Π±ΠΎΡ‚ΠΈ (ΠΏΡ€ΠΈΠ΅ΠΌΠ°ΠΌΠ΅, Ρ‡Π΅ няма 
    // Π΄Π΅Ρ„ΠΈΠ½ΠΈΡ€Π°Π½Π° notDefined Π² глобалния скоуп)
    function example() {
      console.log(notDefined); // => throws a ReferenceError
    }
    
    // ИзвикванС Π½Π° ΠΏΡ€ΠΎΠΌΠ΅Π½Π»ΠΈΠ²Π°, ΠΏΡ€Π΅Π΄ΠΈ дСкларацията ΠΈ Ρ‰Π΅ Ρ€Π°Π±ΠΎΡ‚ΠΈ,
    // Π½ΠΎ стойносттта ΠΈ няма Π΄Π° сС Π²Π·ΠΈΠΌΠ°
     
    function example() {
      console.log(declaredButNotAssigned); // => undefined
      var declaredButNotAssigned = true;
    }
    
    // Π˜Π½Ρ‚Π΅Ρ€ΠΏΡ€Π΅Ρ‚Π°Ρ‚ΠΎΡ€ΡŠΡ‚ поставя Π΄Π΅Ρ„ΠΈΠ½ΠΈΡ€Π°Π½Π΅Ρ‚ΠΎ Π² Π½Π°Ρ‡Π°Π»ΠΎΡ‚ΠΎ
    // Π½Π° скоупа. ΠŸΡ€ΠΈΠΌΠ΅Ρ€ΡŠΡ‚ ΠΌΠΎΠΆΠ΅ Π΄Π° сС ΠΏΡ€Π΅Π½Π°ΠΏΠΈΡˆΠ΅ Ρ‚Π°ΠΊΠ° :
    
    function example() {
      var declaredButNotAssigned;
      console.log(declaredButNotAssigned); // => undefined
      declaredButNotAssigned = true;
    }
  • АнонимнитС Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΈ-ΠΈΠ·Ρ€Π°Π·ΠΈ поставят Π½Π°ΠΉ-Π³ΠΎΡ€Π΅ дСфиницията Π½Π° ΠΏΡ€ΠΎΠΌΠ΅Π½Π»ΠΈΠ²ΠΈ, Π½ΠΎ Π½Π΅ ΠΈ стойността/фунцкията, присвоСна Π½Π° ΠΏΡ€ΠΎΠΌΠ΅Π½Π»ΠΈΠ²Π°Ρ‚Π°.

    function example() {
      console.log(anonymous); // => undefined
    
      anonymous(); // => TypeError anonymous is not a function
    
      var anonymous = function() {
        console.log('anonymous function expression');
      };
    }
  • Π˜ΠΌΠ΅Π½ΡƒΠ²Π°Π½ΠΈΡ‚Π΅ Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΈ-ΠΈΠ·Ρ€Π°Π·ΠΈ ΠΏΡ€Π΅Ρ…Π²ΡŠΡ€Π»ΡΡ‚ ΠΈΠΌΠ΅Ρ‚ΠΎ Π½Π° ΠΏΡ€ΠΎΠΌΠ΅Π½Π»ΠΈΠ²Π°Ρ‚Π°, Π° Π½Π΅ ΠΈΠΌΠ΅Ρ‚ΠΎ Π½Π° функцията ΠΈΠ»ΠΈ тялото ΠΈ.

    function example() {
      console.log(named); // => undefined
    
      named(); // => TypeError named is not a function
    
      superPower(); // => ReferenceError superPower is not defined
    
      var named = function superPower() {
        console.log('Flying');
      };
    }
    
    
    // ΡΡŠΡ‰ΠΎΡ‚ΠΎ Π΅ вярно, ΠΊΠΎΠ³Π°Ρ‚ΠΎ ΠΈΠΌΠ΅Ρ‚ΠΎ Π½Π° функцията
    // Π΅ ΡΡŠΡ‰ΠΎΡ‚ΠΎ ΠΊΠ°Ρ‚ΠΎ ΠΈΠΌΠ΅Ρ‚ΠΎ Π½Π° ΠΏΡ€ΠΎΠΌΠ΅Π½Π»ΠΈΠ²Π°Ρ‚Π°.
    function example() {
      console.log(named); // => undefined
    
      named(); // => TypeError named is not a function
    
      var named = function named() {
        console.log('named');
      }
    }
  • ДСкларацията Π½Π° функцията ΠΏΡ€Π΅Ρ…Π²ΡŠΡ€Π»Ρ ΠΈΠΌΠ΅Ρ‚ΠΎ ΠΈ тялото Π½Π° функция.

    function example() {
      superPower(); // => Flying
    
      function superPower() {
        console.log('Flying');
      }
    }
  • Π—Π° ΠΏΠΎΠ²Π΅Ρ‡Π΅ информация JavaScript Scoping & Hoisting ΠΎΡ‚ Ben Cherry

    [⬆]

  • Π˜Π·ΠΏΠΎΠ»Π·Π²Π°ΠΉΡ‚Π΅ === ΠΈ !== вмСсто == ΠΈ !=.

  • УсловнитС ΠΈΠ·Ρ€Π°Π·ΠΈ сС провСряват Ρ‡Ρ€Π΅Π· ΠΏΡ€Π΅Ρ…Π²ΡŠΡ€Π»ΡΠ½Π΅ към ToBoolean ΠΌΠ΅Ρ‚ΠΎΠ΄ ΠΈ Π²ΠΈΠ½Π°Π³ΠΈ слСдват Ρ‚Π΅Π·ΠΈ прости ΠΏΡ€Π°Π²ΠΈΠ»Π°:

    • Objects става true
    • Undefined става false
    • Null става false
    • Booleans става the value of the boolean
    • Numbers става false Ако +0, -0, or NaN, ΠΈΠ½Π°Ρ‡Π΅ true
    • Strings става false Π°ΠΊΠΎ Π΅ ΠΏΡ€Π°Π·Π΅Π½ Π½ΠΈΠ·'', ΠΈΠ½Π°Ρ‡Π΅ true
    if ([0]) {
      // вярно 
      // Ако ΠΌΠ°ΡΠΈΠ²ΡŠΡ‚ Π΅ ΠΎΠ±Π΅ΠΊΡ‚, ΠΎΠ±Π΅ΠΊΡ‚ΠΈΡ‚Π΅ Π²Ρ€ΡŠΡ‰Π°Ρ‚ true
    }
  • Π˜Π·ΠΏΠΎΠ»Π·Π²Π°ΠΉΡ‚Π΅ ΠΊΡ€Π°Ρ‚ΠΊΠΈ Π²Π°Ρ€ΠΈΠ°Π½Ρ‚ΠΈ.

    // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
    if (name !== '') {
      // ...stuff...
    }
    
    // Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
    if (name) {
      // ...stuff...
    }
    
    // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
    if (collection.length > 0) {
      // ...stuff...
    }
    
    // Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
    if (collection.length) {
      // ...stuff...
    }
  • Π—Π° ΠΏΠΎΠ²Π΅Ρ‡Π΅ информация Truth Equality and JavaScript by Angus Croll

    [⬆]

  • Π˜Π·ΠΏΠΎΠ»Π·Π²Π°ΠΉΡ‚Π΅ скоби с всички ΠΌΠ½ΠΎΠ³ΠΎΡ€Π΅Π΄ΠΎΠ²ΠΈ Π±Π»ΠΎΠΊΠΎΠ²Π΅.

    // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
    if (test)
      return false;
    
    // Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
    if (test) return false;
    
    // Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
    if (test) {
      return false;
    }
    
    // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
    function() { return false; }
    
    // Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
    function() {
      return false;
    }

    [⬆]

  • Π˜Π·ΠΏΠΎΠ»Π·Π²Π°ΠΉΡ‚Π΅ /** ... */ Π·Π° ΠΌΠ½ΠΎΠ³ΠΎΡ€Π΅Π΄ΠΎΠ²ΠΈ ΠΊΠΎΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈ. Π’ΠΊΠ»ΡŽΡ‡Π΅Ρ‚Π΅ обяснСниС, изяснСтС Ρ‚ΠΈΠΏΠΎΠ²Π΅ ΠΈ стойности Π·Π° всички ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€ΠΈ ΠΈ стойности, ΠΊΠΎΠΈΡ‚ΠΎ сС Π²Ρ€ΡŠΡ‰Π°Ρ‚ ΠΎΡ‚ функцията.

    // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
    // make() returns a new element
    // based on the passed in tag name
    //
    // @param <String> tag
    // @return <Element> element
    function make(tag) {
    
      // ...stuff...
    
      return element;
    }
    
    // Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
    /**
     * make() returns a new element
     * based on the passed in tag name
     *
     * @param <String> tag
     * @return <Element> element
     */
    function make(tag) {
    
      // ...stuff...
    
      return element;
    }
  • Π˜Π·ΠΏΠΎΠ»Π·Π²Π°ΠΉΡ‚Π΅ // Π·Π° Π΅Π΄Π½ΠΎΡ€Π΅Π΄ΠΎΠ²ΠΈ ΠΊΠΎΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈ. ΠŸΠΎΡΡ‚Π°Π²ΡΡ‚ΠΉΡ‚Π΅ Π΅Π΄Π½ΠΎΡ€Π΅Π΄ΠΎΠ²ΠΈΡ‚Π΅ ΠΊΠΎΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈ Π½Π° Π½ΠΎΠ² Ρ€Π΅Π΄ Π½Π°Π΄ ΠΏΡ€Π΅Π΄ΠΌΠ΅Ρ‚Π° Π½Π° обяснСниС. ΠŸΠΎΡΡ‚Π°Π²Π΅Ρ‚Π΅ ΠΈ ΠΏΡ€Π°Π·Π΅Π½ Ρ€Π΅Π΄ ΠΏΡ€Π΅Π΄ΠΈ ΠΊΠΎΠΌΠ΅Π½Ρ‚Π°Ρ€Π°.

    // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
    var active = true;  // is current tab
    
    // Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
    // is current tab
    var active = true;
    
    // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
    function getType() {
      console.log('fetching type...'); 
      var type = this._type || 'no type';
    
      return type;
    }
    
    // Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
    function getType() {
      console.log('fetching type...');
    
      var type = this._type || 'no type';
    
      return type;
    }
  • ΠŸΠΎΡΡ‚Π°Π²ΡΠΉΡ‚Π΅ Π² ΠΊΠΎΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΡ‚Π΅ FIXME ΠΈΠ»ΠΈ TODO, ΠΏΠΎΠΌΠ°Π³Π°ΠΉΠΊΠΈ Π½Π° Π΄Ρ€ΡƒΠ³ΠΈ Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚Ρ‡ΠΈΡ†ΠΈ Π΄Π° Ρ€Π°Π·Π±Π΅Ρ€Π°Ρ‚ Π°ΠΊΠΎ ΠΈΠΌΠ° ΠΏΡ€ΠΎΠ±Π»Π΅ΠΌ, ΠΊΠΎΠΉΡ‚ΠΎ трябва Π΄Π° бъдС ΠΏΡ€Π΅Π³Π»Π΅Π΄Π°Π½ ΠΈΠ»ΠΈ Π΄Π° ΠΏΡ€Π΅Π΄Π»Π°Π³Π°Ρ‚Π΅ Ρ€Π΅ΡˆΠ΅Π½ΠΈΠ΅ Π½Π° ΠΏΡ€ΠΎΠ±Π»Π΅ΠΌ. Π’ΠΎΠ²Π° са Ρ€Π°Π·Π»ΠΈΡ‡Π½ΠΈ ΠΎΡ‚ ΠΎΠ±ΠΈΠΊΠ½ΠΎΠ²Π΅Π½ΠΈΡ‚Π΅ ΠΊΠΎΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈ, Π·Π°Ρ‰ΠΎΡ‚ΠΎ Ρ‚Π΅ ΠΏΡ€Π΅Π΄Π»Π°Π³Π°Ρ‚ дСйствиС. FIXME -- need to figure this out or TODO -- need to implement.

  • Π˜Π·ΠΏΠΎΠ»Π·Π²Π°ΠΉΡ‚Π΅ // FIXME: Π΄Π° анонсиратС ΠΏΡ€ΠΎΠ±Π»Π΅ΠΌ

    function Calculator() {
    
      // FIXME: shouldn't use a global here
      total = 0;
    
      return this;
    }
  • Π˜Π·ΠΏΠΎΠ»Π·Π²Π°ΠΉΡ‚Π΅ // TODO: Π΄Π° анонсиратС Ρ€Π΅ΡˆΠ΅Π½ΠΈΠ΅ Π½Π° ΠΏΡ€ΠΎΠ±Π»Π΅ΠΌΠ°

    function Calculator() {
    
      // TODO: total should be configurable by an options param
      this.total = 0;
    
      return this;
    }

  **[[⬆]](#TOC)**


## <a name='whitespace'>ΠŸΡ€Π°Π·Π½ΠΈ ΠΏΠΎΠ»Π΅Ρ‚Π°</a>

- Π˜Π·ΠΏΠΎΠ»Π·Π²Π°ΠΉΡ‚Π΅ Ρ‚Π°Π±ΡƒΠ»Π°Ρ†ΠΈΠΈ с 2 ΠΏΡ€Π°Π·Π½ΠΈ ΠΏΠΎΠ»Π΅Ρ‚Π°

  ```javascript
  // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  function() {
  βˆ™βˆ™βˆ™βˆ™var name;
  }

  // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  function() {
  βˆ™var name;
  }

  // Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  function() {
  βˆ™βˆ™var name;
  }
  ```
- ΠŸΠΎΡΡ‚Π°Π²ΡΠΉΡ‚Π΅ 1 ΠΏΡ€Π°Π·Π½ΠΎ пространство ΠΏΡ€Π΅Π΄ΠΈ Π½Π°Ρ‡Π°Π»Π½Π° скоба.

  ```javascript
  // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  function test(){
    console.log('test');
  }

  // Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  function test() {
    console.log('test');
  }

  // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  dog.set('attr',{
    age: '1 year',
    breed: 'Bernese Mountain Dog'
  });

  // Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  dog.set('attr', {
    age: '1 year',
    breed: 'Bernese Mountain Dog'
  });
  ```
- ΠŸΠΎΡΡ‚Π°Π²ΡΠΉΡ‚Π΅ ΠΏΡ€Π°Π·Π΅Π½ Ρ€Π΅Π΄ Π² края Π½Π° Ρ„Π°ΠΉΠ».

  ```javascript
  // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  (function(global) {
    // ...stuff...
  })(this);
  ```

  ```javascript
  // Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  (function(global) {
    // ...stuff...
  })(this);

  ```

- Π˜Π·ΠΏΠΎΠ»Π·Π²Π°ΠΉΡ‚Π΅ ΠΉΠ΅Ρ€Π°Ρ€Ρ…ΠΈΡ‡Π½ΠΎ подравняванС ΠΏΡ€ΠΈ дълги Π²Π΅Ρ€ΠΈΠ³ΠΈ ΠΎΡ‚ ΠΌΠ΅Ρ‚ΠΎΠ΄ΠΈ.

  ```javascript
  // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  $('#items').find('.selected').highlight().end().find('.open').updateCount();

  // Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  $('#items')
    .find('.selected')
      .highlight()
      .end()
    .find('.open')
      .updateCount();

  // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  var leds = stage.selectAll('.led').data(data).enter().append('svg:svg').class('led', true)
      .attr('width',  (radius + margin) * 2).append('svg:g')
      .attr('transform', 'translate(' + (radius + margin) + ',' + (radius + margin) + ')')
      .call(tron.led);

  // Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  var leds = stage.selectAll('.led')
      .data(data)
    .enter().append('svg:svg')
      .class('led', true)
      .attr('width',  (radius + margin) * 2)
    .append('svg:g')
      .attr('transform', 'translate(' + (radius + margin) + ',' + (radius + margin) + ')')
      .call(tron.led);
  ```

  **[[⬆]](#TOC)**

## <a name='commas'>Π—Π°ΠΏΠ΅Ρ‚Π°ΠΈ</a>

- ЗапСтая Π½Π° Π½ΠΎΠ² Ρ€Π΅Π΄: **НЕ.**

  ```javascript
  // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  var once
    , upon
    , aTime;

  // Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  var once,
      upon,
      aTime;

  // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  var hero = {
      firstName: 'Bob'
    , lastName: 'Parr'
    , heroName: 'Mr. Incredible'
    , superPower: 'strength'
  };

  // Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  var hero = {
    firstName: 'Bob',
    lastName: 'Parr',
    heroName: 'Mr. Incredible',
    superPower: 'strength'
  };
  ```

- Π”ΠΎΠΏΡŠΠ»Π½ΠΈΡ‚Π΅Π»Π½Π° запСтая Π² края: **НЕ.** МоТС Π΄Π° създадС ΠΏΡ€ΠΎΠ±Π»Π΅ΠΌ с IE6/7 ΠΈ IE9. Π‘ΡŠΡ‰ΠΎ, Π² някои Ρ€Π΅Π°Π»ΠΈΠ·Π°Ρ†ΠΈΠΈ Π½Π° ES3 ΠΌΠΎΠΆΠ΅ Π΄Π° Π΄ΠΎΠ±Π°Π²ΠΈ дълТина към масив Π°ΠΊΠΎ ΠΈΠΌΠ° Ρ‚Π°ΠΊΠ°Π²Π° запСтая. Π’ΠΎΠ²Π° Π΅ изяснСно Π² ES5 ([source](http://es5.github.io/#D)):

> ИзданиС 5 изяснява Ρ„Π°ΠΊΡ‚Π°, Ρ‡Π΅ запСтая Π² края Π½Π° ArrayInitialiser Π½Π΅ добавя дълТина към масива. Π’ΠΎΠ²Π° Π½Π΅ Π΅ сСмантина промяна ΠΎΡ‚ ΠΈΠ·Π΄Π°Π½ΠΈΠ΅ 3, Π½ΠΎ някои Ρ€Π΅Π°Π»ΠΈΠ·Π°Ρ†ΠΈΠΈ ΠΌΠΎΠΆΠ΅ Π΄Π° Π±ΡŠΡ€ΠΊΠ°Ρ‚ Ρ‚ΠΎΠ²Π°.

  ```javascript
  // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  var hero = {
    firstName: 'Kevin',
    lastName: 'Flynn',
  };

  var heroes = [
    'Batman',
    'Superman',
  ];

  // Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  var hero = {
    firstName: 'Kevin',
    lastName: 'Flynn'
  };

  var heroes = [
    'Batman',
    'Superman'
  ];
  ```

  **[[⬆]](#TOC)**


## <a name='semicolons'>Π’ΠΎΡ‡ΠΊΠ° ΠΈ запСтая</a>

- **ДА.**

  ```javascript
  // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  (function() {
    var name = 'Skywalker'
    return name
  })()

  // Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  (function() {
    var name = 'Skywalker';
    return name;
  })();

  // Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  ;(function() {
    var name = 'Skywalker';
    return name;
  })();
  ```

  **[[⬆]](#TOC)**


## <a name='type-coercion'>ΠŸΡ€Π΅ΠΎΠ±Ρ€Π°Π·ΡƒΠ²Π°Π½Π΅ Π½Π° Ρ‚ΠΈΠΏΠΎΠ²Π΅</a>

- Π˜Π·ΠΏΡŠΠ»Π½ΡΠ²Π°ΠΉΡ‚Π΅ ΠΏΡ€Π΅ΠΎΠ±Ρ€Π°Π·ΡƒΠ²Π°Π½Π΅Ρ‚ΠΎ Π½Π° Ρ‚ΠΈΠΏΠΎΠ²Π΅ Π² Π½Π°Ρ‡Π°Π»ΠΎΡ‚ΠΎ.
- Низ:

  ```javascript
  //  => this.reviewScore = 9;

  // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  var totalScore = this.reviewScore + '';

  // Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  var totalScore = '' + this.reviewScore;

  // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  var totalScore = '' + this.reviewScore + ' total score';

  // Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  var totalScore = this.reviewScore + ' total score';
  ```

- Use `parseInt` for Numbers and always with a radix for type casting.

  ```javascript
  var inputValue = '4';

  // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  var val = new Number(inputValue);

  // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  var val = +inputValue;

  // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  var val = inputValue >> 0;

  // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  var val = parseInt(inputValue);

  // Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  var val = Number(inputValue);

  // Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  var val = parseInt(inputValue, 10);
  ```


- Π’ случай, Ρ‡Π΅ Ρ€Π΅ΡˆΠΈΡ‚Π΅ Π΄Π° стС ΠΏΠ°Π»Π°Π²ΠΈ с  `parseInt` ΠΈ Ρ‚ΠΎΠ²Π° Π²ΠΈ Π΅ ахилСсовата ΠΏΠ΅Ρ‚Π° ΠΈ Π΅ Π½ΡƒΠΆΠ½ΠΎ Π΄Π° ΠΈΠ·ΠΏΠΎΠ»Π·Π°Ρ‚Π΅ смяна Π½Π° Π±ΠΈΡ‚ΠΎΠ²Π΅ [performance reasons](http://jsperf.com/coercion-vs-casting/3), оставСтС ΠΊΠΎΠΌΠ΅Π½Ρ‚Π°Ρ€ ΠΊΠ°ΠΊΠ²ΠΎ ΠΈ Π·Π°Ρ‰ΠΎ ΠΏΡ€Π°Π²ΠΈΡ‚Π΅.

- **Π—Π°Π±Π΅Π»Π΅ΠΆΠΊΠ°:** Π‘ΡŠΠ΄Π΅Ρ‚Π΅ ΠΏΡ€Π΅Π΄ΠΏΠ°Π·Π»ΠΈΠ²ΠΈ ΠΊΠ°Ρ‚ΠΎ ΠΈΠ·ΠΏΠΎΠ»Π·Π²Π°Ρ‚Π΅ промяна Π½Π° Π±ΠΈΡ‚ΠΎΠ²Π΅. Числата са прСдставСни Ρ‡Ρ€Π΅Π· [64-bit values](http://es5.github.io/#x4.3.19), Π½ΠΎ смяната Π½Π° Π±ΠΈΡ‚ΠΎΠ²Π΅ Π²ΠΈΠ½Π°Π³ΠΈ Π²Ρ€ΡŠΡ‰Π° 32-Π±ΠΈΡ‚ΠΎΠ² ΠΈΠ½Ρ‚ΠΈΠ΄ΠΆΠ΅Ρ€ ([source](http://es5.github.io/#x11.7)). Бмяната Π½Π° Π±ΠΈΡ‚ΠΎΠ²Π΅ ΠΌΠΎΠΆΠ΅ Π΄Π° Π΄ΠΎΠ²Π΅Π΄Π΅ Π΄ΠΎ Π½Π΅ΠΎΡ‡Π°ΠΊΠ²Π°Π½ΠΎ ΠΏΠΎΠ²Π΅Π΄Π΅Π½ΠΈ ΠΏΡ€ΠΈ числови стойности Π½Π° 32 Π±ΠΈΡ‚Π°. [Discussion](https://github.com/airbnb/javascript/issues/109)

  ```javascript
  // Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  /**
   * parseInt бСшС ΠΏΡ€ΠΈΡ‡ΠΈΠ½Π° ΠΊΠΎΠ΄Π° ΠΌΠΈ Π΄Π° Π΅ Π±Π°Π²Π΅Π½.
   * ΠŸΡ€ΠΎΠΌΡΠ½Π°Ρ‚Π° Π½Π° Π±ΠΈΡ‚ΠΎΠ²Π΅ Π² стринга
   * към числа Π³ΠΎ Π½Π°ΠΏΡ€Π°Π²ΠΈ ΠΏΠΎ-Π±ΡŠΡ€Π·.
   */
  var val = inputValue >> 0;
  ```

- Π‘ΡƒΠ»Π΅Π²ΠΈ стойности:

  ```javascript
  var age = 0;

  // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  var hasAge = new Boolean(age);

  // Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  var hasAge = Boolean(age);

  // Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  var hasAge = !!age;
  ```

  **[[⬆]](#TOC)**


## <a name='naming-conventions'>НаимСнуванС ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠΈ</a>

- Π˜Π·Π±ΡΠ³Π²Π°ΠΉΡ‚Π΅ ΠΈΠΌΠ΅Π½Π° ΠΎΡ‚ 1 Π±ΡƒΠΊΠ²Π°. ΠžΠ±ΡΡΠ½ΡΠ²Π°ΠΉΡ‚Π΅ ΠΊΠ°ΠΊΠ²ΠΎ Π½Π°ΠΈΠΌΠ΅Π½ΡƒΠ²Π°Ρ‚Π΅.

  ```javascript
  // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  function q() {
    // ...stuff...
  }

  // Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  function query() {
    // ..stuff..
  }
  ```

- Π˜Π·ΠΏΠΎΠ»Π·Π²Π°ΠΉΡ‚Π΅ camelCase, ΠΊΠΎΠ³Π°Ρ‚ΠΎ ΠΈΠΌΠ΅Π½ΠΎΠ²Π°Ρ‚Π΅ ΠΎΠ±Π΅ΠΊΡ‚ΠΈ, Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΈ, ΠΈ инстанции

  ```javascript
  // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  var OBJEcttsssss = {};
  var this_is_my_object = {};
  function c() {};
  var u = new user({
    name: 'Bob Parr'
  });

  // Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  var thisIsMyObject = {};
  function thisIsMyFunction() {};
  var user = new User({
    name: 'Bob Parr'
  });
  ```

- Π˜Π·ΠΏΠΎΠ»Π·Π²Π°ΠΉΡ‚Π΅ PascalCase ΠΊΠΎΠ³Π°Ρ‚ΠΎ ΠΈΠΌΠ΅Π½ΡƒΠ²Π°Ρ‚Π΅ конструктори ΠΈΠ»ΠΈ класовС

  ```javascript
  // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  function user(options) {
    this.name = options.name;
  }

  var лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ° = new user({
    name: 'nope'
  });

  // Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  function User(options) {
    this.name = options.name;
  }

  var Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ° = new User({
    name: 'yup'
  });
  ```

- Π˜Π·ΠΏΠΎΠ»Π·Π²Π°ΠΉΡ‚Π΅ Π΄ΠΎΠ»Π½ΠΎ Ρ‚ΠΈΡ€Π΅ Π² Π½Π°Ρ‡Π°Π»ΠΎΡ‚ΠΎ `_`, ΠΊΠΎΠ³Π°Ρ‚ΠΎ ΠΈΠΌΠ΅Π½ΡƒΠ²Π°Ρ‚Π΅ частни ΠΏΡ€ΠΎΠΌΠ΅Π½Π»ΠΈΠ²ΠΈ

  ```javascript
  // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  this.__firstName__ = 'Panda';
  this.firstName_ = 'Panda';

  // Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  this._firstName = 'Panda';
  ```

- ΠšΠΎΠ³Π°Ρ‚ΠΎ ΠΈΠ·ΠΏΠΎΠ»Π·Π²Π°Ρ‚Π΅ Ρ€Π΅Ρ„Π΅Ρ€Π΅Π½Ρ†ΠΈΠΈ към `this` ΠΈΠ·ΠΏΠΎΠ»Π·Π²Π°ΠΉΡ‚Π΅ `_this`.

  ```javascript
  // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  function() {
    var self = this;
    return function() {
      console.log(self);
    };
  }

  // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  function() {
    var that = this;
    return function() {
      console.log(that);
    };
  }

  // Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  function() {
    var _this = this;
    return function() {
      console.log(_this);
    };
  }
  ```

- Π˜ΠΌΠ΅Π½ΡƒΠ²Π°ΠΉΡ‚Π΅ си Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΉΡ‚Π΅. Π’ΠΎΠ²Π° Π΅ Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ° Π·Π° прослСдяванС Π½Π° стака.

  ```javascript
  // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  var log = function(msg) {
    console.log(msg);
  };

  // Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  var log = function log(msg) {
    console.log(msg);
  };
  ```

  **[[⬆]](#TOC)**


## <a name='accessors'>Π”ΠΎΡΡ‚ΡŠΠΏΠ²Π°Π½Π΅</a>

- НС са Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΈ Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΈ Π·Π° ΠΏΡ€ΠΎΠΌΠ΅Π½Π»ΠΈΠ²ΠΈ
- Ако ΠΈΠΌΠ° - ΠΏΠΎΠ»Π·Π²Π°ΠΉΡ‚Π΅ ΠΏΠΎΠ΄ΠΎΠ±Π½ΠΈ Π½Π°  getVal() ΠΈ setVal('hello')

  ```javascript
  // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  dragon.age();

  // Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  dragon.getAge();

  // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  dragon.age(25);

  // Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  dragon.setAge(25);
  ```

- Ако ΠΏΡ€ΠΎΠΌΠ΅Π½Π»ΠΈΠ²Π° Π΅ Π±ΡƒΠ»Π΅Π²Π° стойност, ΠΈΠ·ΠΏΠΎΠ»Π·Π²Π°ΠΉΡ‚Π΅ isVal() ΠΈΠ»ΠΈ hasVal()

  ```javascript
  // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  if (!dragon.age()) {
    return false;
  }

  // Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  if (!dragon.hasAge()) {
    return false;
  }
  ```

- МоТС Π΄Π° сС ΡΡŠΠ·Π΄Π°Π΄Π°Ρ‚ get() ΠΈ set() Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΈ, Π½ΠΎ Π±ΡŠΠ΄Π΅Ρ‚Π΅ постоянни с тях.

  ```javascript
  function Jedi(options) {
    options || (options = {});
    var lightsaber = options.lightsaber || 'blue';
    this.set('lightsaber', lightsaber);
  }

  Jedi.prototype.set = function(key, val) {
    this[key] = val;
  };

  Jedi.prototype.get = function(key) {
    return this[key];
  };
  ```

  **[[⬆]](#TOC)**


## <a name='constructors'>ΠšΠΎΠ½ΡΡ‚Ρ€ΡƒΠΊΡ‚ΠΎΡ€</a>

- ΠŸΡ€ΠΈΡΠ²ΠΎΡΠ²Π°ΠΉΡ‚Π΅ ΠΌΠ΅Ρ‚ΠΎΠ΄ΠΈ Π½Π° ΠΏΡ€ΠΎΡ‚ΠΎΡ‚ΠΈΠΏΠ° ΠΎΠ±Π΅ΠΊΡ‚, вмСсто Π΄Π° прСнаписватС ΠΏΡ€ΠΎΡ‚ΠΎΡ‚ΠΈΠΏΠ° с Π½ΠΎΠ² ΠΎΠ±Π΅ΠΊΡ‚. ΠŸΡ€Π΅Π½Π°ΠΏΠΈΡΠ²Π°Π½Π΅Ρ‚ΠΎ Π½Π° ΠΏΡ€ΠΎΡ‚ΠΎΡ‚ΠΈΠΏΠ° ΠΏΡ€Π°Π²ΠΈ наслСдяванСто нСвъзмоТно: ΠΎΡ‚ Π·Π°Π΄Π°Π²Π°Π½Π΅ Π½Π° Π½ΠΎΠ²Π° стойност Π½Π° ΠΏΡ€ΠΎΡ‚ΠΎΡ‚ΠΈΠΏΠ°, прСнаписванС Π±Π°Π·Π°Ρ‚Π°!

  ```javascript
  function Jedi() {
    console.log('new jedi');
  }

  // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  Jedi.prototype = {
    fight: function fight() {
      console.log('fighting');
    },

    block: function block() {
      console.log('blocking');
    }
  };

  // Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  Jedi.prototype.fight = function fight() {
    console.log('fighting');
  };

  Jedi.prototype.block = function block() {
    console.log('blocking');
  };
  ```

- ΠœΠ΅Ρ‚ΠΎΠ΄ΠΈΡ‚Π΅ ΠΌΠΎΠ³Π°Ρ‚ Π΄Π° Π²Ρ€ΡŠΡ‰Π°Ρ‚ `this` ΠΏΠΎΠΌΠ°Π³Π°ΠΉΠΊΠΈ с Π½Π°Π²ΡŠΡ€Π·Π²Π°Π½Π΅Ρ‚ΠΎ Π½Π° ΠΌΠ΅Ρ‚ΠΎΠ΄ΠΈ.

  ```javascript
  // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  Jedi.prototype.jump = function() {
    this.jumping = true;
    return true;
  };

  Jedi.prototype.setHeight = function(height) {
    this.height = height;
  };

  var luke = new Jedi();
  luke.jump(); // => true
  luke.setHeight(20) // => undefined

  // Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  Jedi.prototype.jump = function() {
    this.jumping = true;
    return this;
  };

  Jedi.prototype.setHeight = function(height) {
    this.height = height;
    return this;
  };

  var luke = new Jedi();

  luke.jump()
    .setHeight(20);
  ```


  - МоТС Π΄Π° Π΄Π΅Ρ„ΠΈΠ½ΠΈΡ€Π° ΠΈ toString() ΠΌΠ΅Ρ‚ΠΎΠ΄, просто Π±ΡŠΠ΄Π΅Ρ‚Π΅ сигурни, Ρ‡Π΅ няма странични Π΅Ρ„Π΅ΠΊΡ‚ΠΈ.

  ```javascript
  function Jedi(options) {
    options || (options = {});
    this.name = options.name || 'no name';
  }

  Jedi.prototype.getName = function getName() {
    return this.name;
  };

  Jedi.prototype.toString = function toString() {
    return 'Jedi - ' + this.getName();
  };
  ```

  **[[⬆]](#TOC)**


## <a name='events'>Π‘ΡŠΠ±ΠΈΡ‚ΠΈΡ</a>

  ```javascript 
  // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  $(this).trigger('listingUpdated', listing.id);

  ...

  $(this).on('listingUpdated', function(e, listingId) {
    // do something with listingId
  });
  ```

  ΠΏΡ€Π΅Π΄ΠΏΠΎΡ‡ΠΈΡ‚Π°ΠΉΡ‚Π΅:

  ```javascript
  // Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  $(this).trigger('listingUpdated', { listingId : listing.id });

  ...

  $(this).on('listingUpdated', function(e, data) {
    // do something with data.listingId
  });
  ```

**[[⬆]](#TOC)**


## <a name='modules'>ΠœΠΎΠ΄ΡƒΠ»ΠΈ</a>

- ΠœΠΎΠ΄ΡƒΠ» трябва Π΄Π° Π·Π°ΠΏΠΎΡ‡Π²Π° с `!`. Π’ΠΎΠ²Π° осигурява, Ρ‡Π΅ Π΄ΠΎΡ€ΠΈ Π΄Ρ€ΡƒΠ³ ΠΌΠΎΠ΄ΡƒΠ» Π΄Π° Π΅ Π·Π°Π±Ρ€Π°Π²ΠΈΠ» Π΄Π° постави Π½Π° края Ρ‚ΠΎΡ‡ΠΊΠ° ΠΈ запСтая, няма Π΄Π° ΠΈΠΌΠ° Π³Ρ€Π΅ΡˆΠΊΠΈ Π² продукция, ΠΊΠΎΠ³Π°Ρ‚ΠΎ скриптовСтС сС ΠΊΠΎΠ½ΠΊΠ°Ρ‚Π΅Π½ΠΈΡ€Π°Ρ‚. [Explanation](https://github.com/airbnb/javascript/issues/44#issuecomment-13063933)

- Π€Π°ΠΉΠ»ΡŠΡ‚ сС Π½Π°ΠΈΠΌΠ΅Π½ΡƒΠ²Π° с camelCase, Π² ΠΏΠ°ΠΏΠΊΠ° със ΡΡŠΡ‰ΠΎΡ‚ΠΎ ΠΈΠΌΠ΅.


- Π”ΠΎΠ±Π°Π²Π΅Ρ‚Π΅ ΠΌΠ΅Ρ‚ΠΎΠ΄, ΠΊΠ°Π·Π²Π°Ρ‰ сС noConflict(), поставящ СкспортиранитС ΠΌΠΎΠ΄ΡƒΠ»ΠΈ към ΠΏΡ€Π΅Π΄ΠΈΡˆΠ½Π° вСрсия ΠΈ Π²Ρ€ΡŠΡ‰Π°Ρ‰ Ρ‚ΠΎΠ·ΠΈ.

- Π”Π΅ΠΊΠ»Π°Ρ€ΠΈΡ€Π°ΠΉΡ‚Π΅ `'use strict';` Π² Π½Π°Ρ‡Π°Π»ΠΎΡ‚ΠΎ Π½Π° ΠΌΠΎΠ΄ΡƒΠ».

  ```javascript
  // fancyInput/fancyInput.js

  !function(global) {
    'use strict';

    var previousFancyInput = global.FancyInput;

    function FancyInput(options) {
      this.options = options || {};
    }

    FancyInput.noConflict = function noConflict() {
      global.FancyInput = previousFancyInput;
      return FancyInput;
    };

    global.FancyInput = FancyInput;
  }(this);
  ```

  **[[⬆]](#TOC)**


## <a name='jquery'>jQuery</a>

- ΠŸΠΎΡΡ‚Π°Π²Π΅Ρ‚Π΅ jQuery ΠΎΠ±Π΅ΠΊΡ‚ΠΈ ΠΏΡ€ΠΎΠΌΠ΅Π½Π»ΠΈΠ²ΠΈ с `$`.

  ```javascript
  // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  var sidebar = $('.sidebar');

  // Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  var $sidebar = $('.sidebar');
  ``` 

  ```javascript
  // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  function setSidebar() {
    $('.sidebar').hide();

    // ...stuff...

    $('.sidebar').css({
      'background-color': 'pink'
    });
  }

  // Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  function setSidebar() {
    var $sidebar = $('.sidebar');
    $sidebar.hide();

    // ...stuff...

    $sidebar.css({
      'background-color': 'pink'
    });
  }
  ```

//- For DOM queries use Cascading `$('.sidebar ul')` or parent > child `$('.sidebar > ul')`. [jsPerf](http://jsperf.com/jquery-find-vs-context-sel/16)
- Π—Π° DOM Ρ‚ΡŠΡ€ΡΠ΅Π½Π΅ ΠΈΠ·ΠΏΠΎΠ»Π·Π²Π°ΠΉΡ‚Π΅ каскадно `$('.sidebar ul')` or parent > child `$('.sidebar > ul')`. [jsPerf](http://jsperf.com/jquery-find-vs-context-sel/16)
- Use `find` with scoped jQuery object queries.
- Π˜Π·ΠΏΠΎΠ»Π·Π²Π°ΠΉΡ‚Π΅ `find` Π² jQuery Π·Π° ΠΏΠΎ-лСсно Π½Π°ΠΌΠΈΡ€Π°Π½Π΅ Π² скоуп.

  ```javascript
  // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  $('ul', '.sidebar').hide();

  // лоша ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  $('.sidebar').find('ul').hide();

  // Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  $('.sidebar ul').hide();

  // Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  $('.sidebar > ul').hide();

  // Π΄ΠΎΠ±Ρ€Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ°
  $sidebar.find('ul');
  ```

  **[[⬆]](#TOC)**


## <a name='es5'>ECMAScript 5 Π‘ΡŠΠ²ΠΌΠ΅ΡΡ‚ΠΈΠΌΠΎΡΡ‚</a>

- ΠžΡ‚Π½Π°ΡΡ сС [Kangax](https://twitter.com/kangax/)'s ES5 [compatibility table](http://kangax.github.com/es5-compat-table/)

**[[⬆]](#TOC)**


## <a name='testing'>ВСстванС</a>

- **ДА.**

  ```javascript
  function() {
    return true;
  }
  ```

  **[[⬆]](#TOC)**


## <a name='performance'>ИзпълнСниС</a>

- [On Layout & Web Performance](http://kellegous.com/j/2013/01/26/layout-performance/)
- [String vs Array Concat](http://jsperf.com/string-vs-array-concat/2)
- [Try/Catch Cost In a Loop](http://jsperf.com/try-catch-in-loop-cost)
- [Bang Function](http://jsperf.com/bang-function)
- [jQuery Find vs Context, Selector](http://jsperf.com/jquery-find-vs-context-sel/13)
- [innerHTML vs textContent for script text](http://jsperf.com/innerhtml-vs-textcontent-for-script-text)
- [Long String Concatenation](http://jsperf.com/ya-string-concat)
- Loading...

**[[⬆]](#TOC)**


## <a name='resources'>РСсурси</a>


**ΠŸΡ€ΠΎΡ‡Π΅Ρ‚Π΅Ρ‚Π΅ Ρ‚ΠΎΠ²Π°**

- [Annotated ECMAScript 5.1](http://es5.github.com/)

**Π”Ρ€ΡƒΠ³ΠΈ стилови Ρ€ΡŠΠΊΠΎΠ²ΠΎΠ΄ΡΡ‚Π²Π°**

- [Google JavaScript Style Guide](http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml)
- [jQuery Core Style Guidelines](http://docs.jquery.com/JQuery_Core_Style_Guidelines)
- [Principles of Writing Consistent, Idiomatic JavaScript](https://github.com/rwldrn/idiomatic.js/)

**Π”Ρ€ΡƒΠ³ΠΈ стиловС**

- [Naming this in nested functions](https://gist.github.com/4135065) - Christian Johansen
- [Conditional Callbacks](https://github.com/airbnb/javascript/issues/52)
- [Popular JavaScript Coding Conventions on Github](http://sideeffect.kr/popularconvention/#javascript)

**Π”ΠΎΠΏΡŠΠ»Π½ΠΈΡ‚Π΅Π»Π½ΠΈ**

- [Understanding JavaScript Closures](http://javascriptweblog.wordpress.com/2010/10/25/understanding-javascript-closures/) - Angus Croll
- [Basic JavaScript for the impatient programmer](http://www.2ality.com/2013/06/basic-javascript.html) - Dr. Axel Rauschmayer

**Книги**

- [JavaScript: The good Parts](http://www.amazon.com/JavaScript-good-Parts-Douglas-Crockford/dp/0596517742) - Douglas Crockford
- [JavaScript Patterns](http://www.amazon.com/JavaScript-Patterns-Stoyan-Stefanov/dp/0596806752) - Stoyan Stefanov
- [Pro JavaScript Design Patterns](http://www.amazon.com/JavaScript-Design-Patterns-Recipes-Problem-Solution/dp/159059908X)  - Ross Harmes and Dustin Diaz
- [High Performance Web Sites: Essential Knowledge for Front-End Engineers](http://www.amazon.com/High-Performance-Web-Sites-Essential/dp/0596529309) - Steve Souders
- [Maintainable JavaScript](http://www.amazon.com/Maintainable-JavaScript-Nicholas-C-Zakas/dp/1449327680) - Nicholas C. Zakas
- [JavaScript Web Applications](http://www.amazon.com/JavaScript-Web-Applications-Alex-MacCaw/dp/144930351X) - Alex MacCaw
- [Pro JavaScript Techniques](http://www.amazon.com/Pro-JavaScript-Techniques-John-Resig/dp/1590597273) - John Resig
- [Smashing Node.js: JavaScript Everywhere](http://www.amazon.com/Smashing-Node-js-JavaScript-Everywhere-Magazine/dp/1119962595) - Guillermo Rauch
- [Secrets of the JavaScript Ninja](http://www.amazon.com/Secrets-JavaScript-Ninja-John-Resig/dp/193398869X) - John Resig and Bear Bibeault
- [Human JavaScript](http://humanjavascript.com/) - Henrik Joreteg
- [Superhero.js](http://superherojs.com/) - Kim Joar Bekkelund, Mads Mobæk, & Olav Bjorkoy
- [JSBooks](http://jsbooks.revolunet.com/)

**Π‘Π»ΠΎΠ³ΠΎΠ²Π΅**

- [DailyJS](http://dailyjs.com/)
- [JavaScript Weekly](http://javascriptweekly.com/)
- [JavaScript, JavaScript...](http://javascriptweblog.wordpress.com/)
- [Bocoup Weblog](http://weblog.bocoup.com/)
- [Adequately good](http://www.adequatelygood.com/)
- [NCZOnline](http://www.nczonline.net/)
- [Perfection Kills](http://perfectionkills.com/)
- [Ben Alman](http://benalman.com/)
- [Dmitry Baranovskiy](http://dmitry.baranovskiy.com/)
- [Dustin Diaz](http://dustindiaz.com/)
- [nettuts](http://net.tutsplus.com/?s=javascript)

**[[⬆]](#TOC)**

## <a name='in-the-wild'>КъдС сС ΠΈΠ·ΠΏΠΎΠ»Π·Π²Π°Ρ‚ Ρ‚Π΅Π·ΠΈ ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠΈ</a>


- **Aan Zee**: [AanZee/javascript](https://github.com/AanZee/javascript)
- **Airbnb**: [airbnb/javascript](https://github.com/airbnb/javascript)
- **American Insitutes for Research**: [AIRAST/javascript](https://github.com/AIRAST/javascript)
- **Compass Learning**: [compasslearning/javascript-style-guide](https://github.com/compasslearning/javascript-style-guide)
- **ExactTarget**: [ExactTarget/javascript](https://github.com/ExactTarget/javascript)
- **Gawker Media**: [gawkermedia/javascript](https://github.com/gawkermedia/javascript)
- **GeneralElectric**: [GeneralElectric/javascript](https://github.com/GeneralElectric/javascript)
- **GoodData**: [gooddata/gdc-js-style](https://github.com/gooddata/gdc-js-style)
- **Grooveshark**: [grooveshark/javascript](https://github.com/grooveshark/javascript)
- **How About We**: [howaboutwe/javascript](https://github.com/howaboutwe/javascript)
- **Mighty Spring**: [mightyspring/javascript](https://github.com/mightyspring/javascript)
- **MinnPost**: [MinnPost/javascript](https://github.com/MinnPost/javascript)
- **ModCloth**: [modcloth/javascript](https://github.com/modcloth/javascript)
- **National Geographic**: [natgeo/javascript](https://github.com/natgeo/javascript)
- **National Park Service**: [nationalparkservice/javascript](https://github.com/nationalparkservice/javascript)
- **Razorfish**: [razorfish/javascript-style-guide](https://github.com/razorfish/javascript-style-guide)
- **Shutterfly**: [shutterfly/javascript](https://github.com/shutterfly/javascript)
- **Userify**: [userify/javascript](https://github.com/userify/javascript)
- **Zillow**: [zillow/javascript](https://github.com/zillow/javascript)
- **ZocDoc**: [ZocDoc/javascript](https://github.com/ZocDoc/javascript)

## <a name='translation'>ΠŸΡ€Π΅Π²ΠΎΠ΄ΠΈ</a>

Π”Ρ€ΡƒΠ³ΠΈ ΠΏΡ€Π΅Π²ΠΎΠ΄ΠΈ

- :de: **НСмски**: [timofurrer/javascript-style-guide](https://github.com/timofurrer/javascript-style-guide)
- :jp: **Японски**: [mitsuruog/javacript-style-guide](https://github.com/mitsuruog/javacript-style-guide)
- :br: **ΠŸΠΎΡ€Ρ‚ΠΎΠ³Π°Π»ΡΠΊΠΈ**: [armoucar/javascript-style-guide](https://github.com/armoucar/javascript-style-guide)
- :cn: **ΠšΠΈΡ‚Π°ΠΉΡΠΊΠΈ**: [adamlu/javascript-style-guide](https://github.com/adamlu/javascript-style-guide)
- :es: **Испански**: [paolocarrasco/javascript-style-guide](https://github.com/paolocarrasco/javascript-style-guide)
- :kr: **ΠšΠΎΡ€Π΅ΠΉΡΠΊΠΈ**: [tipjs/javascript-style-guide](https://github.com/tipjs/javascript-style-guide)
- :fr: **ЀрСнски**: [nmussy/javascript-style-guide](https://github.com/nmussy/javascript-style-guide)
- :ru: **Руски**: [sbezludny/javascript-style-guide](https://github.com/sbezludny/javascript-style-guide)
- :bg: **Π‘ΡŠΠ»Π³Π°Ρ€ΡΠΊΠΈ**: [borislavvv/javascript-style-guide](https://github.com/sbezludny/javascript-style-guide)

## <a name='guide-guide'>JavaScript Π‘Ρ‚ΠΈΠ»ΠΎΠ²ΠΎ Ρ€ΡŠΠΊΠΎΠ²ΠΎΠ΄ΡΡ‚Π²ΠΎ</a>

- [Reference](https://github.com/airbnb/javascript/wiki/The-JavaScript-Style-Guide-Guide)

## <a name='authors'>Π‘ΡŠΡ‚Ρ€ΡƒΠ΄Π½ΠΈΡ†ΠΈ</a>

- [View Contributors](https://github.com/airbnb/javascript/graphs/contributors)


## <a name='license'>Π›ΠΈΡ†Π΅Π½Π·</a>

(The MIT License)

Copyright (c) 2012 Airbnb

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

**[[⬆]](#TOC)**

# };

About

JavaScript Style Guide

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published