ES6 variables

JS Modules

AirBnB

Evening talk

ES6 Variables

  • Block Scope ( we don't have opportunity to call it outside )
  • Actual values for a loops
  • Exist Const value ( for primitive & for object's reference)

P.S.   Const  !==  Immutable

ES6 Arrow Function

  • Shorter description ( especially good as callback )
  • Absence of this ( use this from outer scope )

ES6 Features

Code time

Modules in JS

  • It's a piece of code that is executed once it is loaded
  • DRY ( Don't Repeat Yourself)
  • Easier maintainability
  • If a module is imported multiple times, only a single “instance” of it exists.

 

IIFE

Immediate Invoked Functional Expression

  • Useful for separating code
  • Used to create "global" modules

Code time

AMD

  • Inspired by real world experience with XHR + eval()
  • Used to load asynchronously dependencies
  • Can work without build process

A Format For Writing Modular JavaScript In The Browser

AMD

Module Definition

define('myModule', 
  ['foo', 'bar'],
  function ( foo, bar ) {
    var myModule = {
      doStuff: function(){
        console.log('Call me maybe!');
       }
    } 

    return myModule;
});

AMD

Module Using

require(['app/myModule'], 
  function( myModule ) {
    var module = new myModule();
    module.doStuff();
});

Common JS

A Module Format Optimized For The Server

  • Standard way to declare module with Node.js
  • Synchronous approach to import module

Code time

Harmony JS

Modules Of The Future

  • Modern way to work with modules
  • Fits for server & for clients
  • import - keyword for bind export module as local variable
  • export - used to provide module ( readonly )

Code time

  • Is not supported  by native code ( Babel is needed )

Code Style

AirBnB

JS Modules, ES6 var, AirBnB

By Anton Bely

JS Modules, ES6 var, AirBnB

  • 1,396