ES6 in Depth
  • Introduction
  • Installation
  • Block Scope
    • Constant
    • Use cases
  • Template String
    • New String Methods
    • Tagged Template Literal
  • New Number Methods
  • Arrow Function
    • Default Parameters
    • Lexical This Scope
    • Where not to use arrow function
  • Object Enhancement
  • New Array Methods
    • For Of
  • Spread Operator
  • Destructuring
    • Array Destructuring
  • Class
  • Symbols
  • New Data Structures
    • Set
    • Map
    • WeakSet
    • WeakMap
    • Iterators
    • Generators
  • Promise
  • Import Export
Powered by GitBook
On this page
  • 1
  • 2
  • 4

Was this helpful?

  1. Arrow Function

Where not to use arrow function

1

var btn = document.querySelector('.btn');

btn.addEventListiner('click', function(){
    console.log(this); // this referes to button clicked on
});

2

var person = { points: 10, score: function(){ this.points++; } };

person.score(); // 11 person.score(); // 12 person.score(); // 13

## 3

```javascript
class Person{
    constructor(name){
        this.name = name
    }
}

var p = new Person('Hemant');

Person.prototype.sayName = function(){
    console.log('My name is ' + this.name);    
};

p.sayName(); // My name is Hemant

4

var myFun = () => {
    console.log(arguments); //     Uncaught ReferenceError: arguments is not defined
};
PreviousLexical This ScopeNextObject Enhancement

Last updated 4 years ago

Was this helpful?