Monday, May 8, 2017

Spread syntax or Spread operator ...


The spread syntax allows an expression to be expanded in places where multiple arguments (for function calls) or multiple elements (for array literals) or multiple variables (for destructuring assignment) are expected.

Syntax

For function calls:
myFunction(...iterableObj); 
For array literals:
[...iterableObj, 4, 5, 6]; 
@reference_1_mozilla_Spread_operator

Bonding arrays contained in an array of objects using the spread operator and initialValue

@reference_2_mozilla_Reduce

 Rest parameters

@reference_3_mozilla_rest_parameters

 

Tuesday, May 2, 2017

JavaScript Scope & 'this' keyword

There are also problems that we run into when dealing with the this value, for instance if I do this, even inside the same function the scope can be changed and the this value can be changed:


var nav = document.querySelector('.nav'); // <nav class="nav">
var toggleNav = function () {
  console.log(this); // <nav> element
  setTimeout(function () {
    console.log(this); // [object Window]
  }, 1000);
};
nav.addEventListener('click', toggleNav, false);

So what’s happened here? We’ve created new scope which is not invoked from our event handler, so it defaults to the window Object as expected.

@reference_1_toddmotto.com

An anonymous function this will refer to the window object on the global scope.

@reference_2_stackoverflow

this
@reference_3_mozilla