ES5-> ES6

ES5 to ES2015 difference.

by kontrach

HTML

ES5 -> ES2015

JavaScript

// [start] String

// check if https
var protocol = window.location.protocol;
// ES5
if (protocol.indexOf('s') > -1) {
    // https
}
//ES6
if (protocol.includes('s')) {}// https
// or 
if (protocol.endsWith('s:')) {}
// or
if (window.location.href.startsWith('https')) {}

// string repeatition
// es5
function repeat(str, times, separator) {
  var defaultTimes = 3;
  var defaultSeparator = '';
  return Array.apply(Array, {length: times || defaultTimes})
    .map(function(n){
      return str
    })
    .join(separator || defaultSeparator);
}
// es6 version of function
const repeatES6 = (str, times = 3, separator = '') => 
	Array(times).fill(1).map(_ => str).join(separator);

// es6 String.prototype.repeat. unfortunatelly, only one parameter. There is no option for separator param.
'hello'.repeat(3)// 'hellohellohello';
// [end] String