ES2015+ Walkthrough
New Builtin APIs
Part I
Strings
New Instance Methods
'blah'.includes('la');
'blah'.startsWith('bl');
'blah'.endsWith('la', 3);
'blah'.repeat(3);
'blah'.codePointAt(2);
Strings
New static Methods
String.fromCodePoint(97);
String.fromCodePoint(0x103);
String.fromCodePoint()
vs.
String.fromCharCode()
Template Strings
var user = 'gsklee';
var responseType = 'application/json';
console.log(
`https://api.github.com/users/${user}
Content-Type: ${responseType}`
);
Tagged Template Strings
var user = 'gsklee';
function GET () {
return fetch(arguments[0].raw[0] + arguments[1])
.then(function (response) {
return response.json();
});
}
GET `https://api.github.com/users/${user}`
.then(function (json) {
console.log(json);
});
Strings
New static Methods
var user = 'gsklee';
var responseType = 'application/json';
function GET () {
console.log(String.raw.apply(this, arguments));
}
GET `https://api.github.com/users/${user}
Content-Type: ${responseType}`;
Numbers
Number.EPSILON;
Number.MAX_SAFE_INTEGER;
Number.MIN_SAFE_INTEGER;
New Properties
Numbers
Number.isFinite(Infinity);
Number.isInteger(Infinity);
Number.isNaN(0 / 0);
Number.isSafeInteger(Math.pow(2, 53) - 1);
Number.parseFloat('3.14');
Number.parseInt('3.14', 10);
New static Methods
Number.isFinite()
vs.
isFinite()
etc.
Binary & Octal Literals
0b1010101 === 85;
0o1010101 === 266305;
Maths
Math.acosh(1);
Math.asinh(1);
Math.atanh(1);
Math.cbrt(8);
Math.clz32(1);
Math.cosh(1);
Math.expm1(1);
Math.hypot(3, 4);
Math.imul(3, 4);
Math.log1p(1);
Math.log10(1);
Math.log2(1);
Math.sinh(1);
Math.tanh(1);
New static Methods
Maths
Math.fround(Math.PI);
Math.sign(-Infinity);
Math.trunc(42.84);
Math.trunc(-1.123);
New static Methods
Functions
function foo () {}.name;
/* Babel Only */
var bar = function () {};
bar.name;
New Instance Methods
Arrays
[1, 2, 3, 4, 5].copyWithin(1, 3);
[1, 2, 3, 4, 5].fill(42);
function finder (value) {
return value === 5;
}
[1, 2, 3, 4, 5].find(finder);
[1, 2, 3, 4, 5].findIndex(finder);
New Instance Methods
Arrays
[1, 2, 3, 4, 5].includes(1);
New Instance Methods (ES2016)
Arrays
Array.of(42);
Array.from(document.querySelectorAll('a')).map(function (a) {
return a.innerHTML;
});
function sum () {
return Array.from(arguments).reduce(function (x, y) {
return x + y;
});
}
sum(1, 2, 3, 4, 5);
New static Methods
ES2015+ Walkthrough, Part I: New Builtin APIs
By G. Kay Lee
ES2015+ Walkthrough, Part I: New Builtin APIs
- 5,520