rse / es6-features

ECMAScript 6: Feature Overview & Comparison

Home Page: https://rse.github.io/es6-features/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add listings of new built-in methods

webbedspace opened this issue · comments

commented

Here's some ES5 equivalents of a few such methods to get you started.

Object.assign:

var src1 = { foo: 1, bar: 2 };
var src2 = { foo: 3, baz: 3 };
var dst = {};
Object.keys(src).forEach(function(e) {
  dst[e] = src[e];
});
Object.keys(src2).forEach(function(e) {
  dst[e] = src2[e];
});
dst.foo; // 3
dst.bar; // 2
dst.baz; // 3

Array.find:

[1,3,4,2].filter(function(e) { return e > 3; })[0]; // 4

String.prototype.repeat:

(Array(12)+",").replace(/,/g, "red"); // "redredredredredredredredredredredred"

@webbedspace Array(13).join('red')

Ok, added multiple examples related to new built-in methods, including your examples. Thanks for your contribution.