Giter VIP home page Giter VIP logo

es7-features's Introduction

ECMAScript 7 is the next evolution of the ECMA-262 standard, this is at a very early stage, you may want to checkout paws-on-es6 and jsfeatures.in as well.

List of ES7 features:

Exponentiation Operator

Performs exponential calculation on operands. Same algorithm as Math.pow(x, y)

Stage: Draft.

let cubed = x => x ** 3;

cubed(2) // 8;

Async functions

Deferred Functions

Stage: Proposal.

function wait(t){
  return new Promise((r) => setTimeout(r, t));
}

async function asyncMania(){
  console.log("1");
  await wait(1000);
  console.log("2");
}

asyncMania()
.then(() => console.log("3"));

// logs: 1 2 3

Async generators

Deferred generators.

Stage: Proposal.

// provider
async function* nums() {
  yield 1;
  yield 2;
  yield 3;
}

// consumer
async function printData() {
  for(var x on nums()) {
    console.log(x);
  }
}

Object.getOwnPropertyDescriptors

Returns a property descriptor for an own property.

Stage: Strawman.

// Creating a shallow copy.
var shallowCopy = Object.create(
  Object.getPrototypeOf(originalObject),
  Object.getOwnPropertyDescriptors(originalObject)
);

Object.values

Get all the values of the object as an array.

Stage: Shall reach Strawman

var person = { fname: "Hemanth", lname: "HM", location: "Earth", type: "Human" };

Object.values(person);

//^ ["Hemanth","HM","Earth","Human"]

Object.entries

Returns a Array of arrays of key,value pairs.

Stage: Shall reach Strawman

var person = { fname: "Hemanth", lname: "HM", location: "Earth", type: "Human" };

Object.entries(person);

//^ [["fname","Hemanth"],["lname","HM"],["location","Earth"],["type","Human"]]

Array.prototype.includes

Determines whether an array includes a certain element or not.

Stage: Draft.

[1, 2, 3].includes(3, 0, 7); // true
[1, 2, NaN].includes(NaN); // true
[0,+1,-1].includes(42); // false

Typed Objects

Portable, memory-safe, efficient, and structured access to contiguously allocated data.

Stage: Proposal.

var Point = new StructType({
  x: int32,
  y: int32
});

var point = new Point({
  x: 42,
  y: 420
});

Trailing commas in function syntax.

Trailing commas in parameter and argument lists.

Stage: Proposal

var meow = function (cat1, cat2,) {}

Math.max(4,2,0,);

Class decorators.

Annotate and modify classes and properties at design time.

Stage: Proposal.

class Person {
  @cantEnum
  get kidCount() { return this.children.length; }
}

function cantEnum(target, name, descriptor) {
  descriptor.enumerable = false;
  return descriptor;
}

Class properties

Properties of class.

Stage: Strawman.

class Cat {
  name = 'Garfield';
  static says = 'meow';
}
new Cat().name; // Garfield
Cat.says; // meow

Map.prototype.toJSON

toJSON for Maps.

Stage: Strawman.

var myMap = new Map();
myMap.set(NaN, "not a number");

console.log(myMap.toJSON()); // {"NaN":"not a number"}

Set.prototype.toJSON

toJSON for Sets.

Stage: Strawman.

var mySet = new Set();
mySet.add(NaN);
mySet.add(1);
console.log(mySet.toJSON()) // {"1":1,"NaN":null}

String.prototype.at

String containing the code point at the given position

Stage: Strawman.

'abc\uD834\uDF06def'.at(1) // 'b'
'abc\uD834\uDF06def'.at(3) // '\uD834\uDF06'

Object rest properties

Rest properties for object destructuring assignment.

Stage: Strawman.

let { fname, lname, ...rest } = { fname: "Hemanth", lname: "HM", location: "Earth", type: "Human" };
fname; //"Hemanth"
lname; //"HM"
rest; // {location: "Earth", type: "Human"}

Object spread properties

Spread properties for object destructuring assignment.

Stage: Strawman.

let info = {fname, lname, ...rest};

info; // { fname: "Hemanth", lname: "HM", location: "Earth", type: "Human" }

String.prototype.padLeft

left justify and pad strings.

Stage: Strawman.

"hello".padLeft(4)            #=> "hello"
"hello".padLeft(20)           #=> "hello               "
"hello".padLeft(20, '1234')   #=> "hello123412341234123"

String.prototype.padRight

right justify and pad strings.

Stage: Strawman.

"hello".padRight(4)            #=> "hello"
"hello".padRight(20)           #=> "               hello"
"hello".padRight(20, '1234')   #=> "123412341234123hello"

String.prototype.trimLeft

left trims the string.

Stage: Candidate.

' \t \n LeftTrim   \t\n'.trimLeft(); // 'LeftTrim   \t\n';

String.prototype.trimRight

right trims the string.

Stage: Candidate.

' \t \n RightTrim   \t\n'.trimRight(); // ' \t \n RightTrim';

Regexp.escape

Escapes any characters that would have special meaning in a regular expression.

Stage: Strawaman

RegExp.escape("(*.*)"); // "\(\*\.\*\)"
RegExp.escape("。^・ェ・^。") // "。\^・ェ・\^。"
RegExp.escape("😊 *_* +_+ ... 👍"); // "😊 \*_\* \+_\+ \.\.\. 👍"

Bind Operator

:: Function binding and method extraction

Stage: Shall reach Strawman.

let log = (level, msg) => ::console[level](msg);

import { map, takeWhile, forEach } from "iterlib";

getPlayers()
  ::map(x => x.character())
  ::takeWhile(x => x.strength > 100)
  ::forEach(x => console.log(x));

Reflect.Realm

TDB

es7-features's People

Contributors

hemanth avatar lvendrame avatar jisaacks avatar mapreal19 avatar thomheymann avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.