Search Features: Arrow Functions
Search Features: Arrow Functions
SEARCH FEATURES
🔍 Search features
Arrow functions
Lexical this, shoter functions.
let obj = {
method: function () {
return () => this;
}
};
//Due to lexical scope obj.method()() <=
Block Scope
Declares a block scope local variable,
optionally initializing it to a value.
class
Syntactical sugar over prototype-based
inheritance.
class Person {
https://jsfeatures.in/#ES6 1/9
4/10/2020 JS features
constructor(name) {
this.name = name;
this.movement = "walks";
}
move(meters) {
console.log(`${this.name} ${this.mov
}
}
move() {
super.move(500);
}
}
clark.move(100);
//-> Clark Kent walks 100m.
superman.move();
//-> Superman flies 500m.
class Base {}
class Derived extends Base {}
var obj = {
[foo + bar]: "o_0",
[foo + baz]: "0_o",
foo: "foo",
bar: "bar",
baz: "baz"
};
console.log(obj.foobar); //o_0
console.log(obj.foobaz); //0_o
https://jsfeatures.in/#ES6 2/9
4/10/2020 JS features
Default Params
Initialize formal parameters with default values,
if no value or undefined is passed.
Destructuring
Extract data from arrays or objects.
Direct Proxy
Define custom behavior for fundamental
operations of an object.
/*
* Negative array indices:
* array = NegativeIndices [4, 420, 42]
* array[-1] is 42
*/
https://jsfeatures.in/#ES6 3/9
4/10/2020 JS features
for-of loop
Loop over Iterator objects.
Generators
The function* declaration defines a generator
function, which returns a Generator object.
function *Counter(){
var n = 0;
while(1 < 2) {
yield n;
++n;
}
}
Map
Map object is a simple and effective key/value
data-structure.
modules
Module format common to CommonJS and
AMD.
https://jsfeatures.in/#ES6 4/9
4/10/2020 JS features
/* In math.js */
export function div(x, y) {
return x / y;
}
export var pi = 3.141593;
//In index.js
import {div, pi} from math;
var greet = {
__proto__: theProtoObj,
handler, //Instead of handler: handler
world: () => "Hello World!",
toString() {
return "Results: " + super.toString(
}
};
property-method-assignment
Method syntax is supported in object initializers.
let person = {
get name() {
return this._name;
},
set name(val){
console.log("Setting name: " + val);
this._name = val;
}
};
/*
> person.name = "Hemanth"
"Hemanth"
"Setting name: Hemanth"
> person.name
"Hemanth"
Rest params
https://jsfeatures.in/#ES6 5/9
4/10/2020 JS features
console.log(sortRestArgs(5,2,7,1)) //[1,
Set
Store unique values of any type.
cards.has('♠'); //true
cards.has('joker'); //false
cards.size; //4
/*
Would log:
♠
♥
♦
♣
*/
cards.add('♣');
Spread operator
Expanded in places with `...` for arguments or
multiple elements.
https://jsfeatures.in/#ES6 6/9
4/10/2020 JS features
Symbol
Unique and immutable data type.
function Cat(name) {
this[nameSymbl] = name;
}
Cat.prototype.getName = function() {
return this[nameSymbl];
};
return Cat;
}());
Tail recursion
Tail Calls, Optimization.
Template Literals
Better string formatting capabilities.
Unicode in Regex
Unicode aware regex.
https://jsfeatures.in/#ES6 7/9
4/10/2020 JS features
WeakMap
key/value pairs, keys are objects and the
values can be arbitrary values, references to
key objects are held "weakly".
wm.set(wmk,'life');
wm.get(wmk); //"life"
wm.has(wmk); //true
wm.delete(wmk); //true
wm.has(wmk); //false
WeakSet
Store weakly held objects in a collection.
ws.add(window);
ws.add(foo);
ws.has(window); //true
ws.has(bar); //false, bar has not been a
https://jsfeatures.in/#ES6 8/9
4/10/2020 JS features
© 2018
https://jsfeatures.in/#ES6 9/9