title: Cannot set property 'value' of undefined inside es6 class
body: <p>Upon writing code in es6 following a tutorial, I get error -</p>
  
  <pre><code>class APromise {
    constructor(fn) {
      this.state = 'pending';
      this.value = null;
      this.deferred = undefined;
      fn(this.resolve);
    }
  
    resolve(newValue) {
      this.value = newValue;    // ERROR HERE
      this.state = 'resolved';
      if (this.deferred) {
        this.handle(this.deferred);
      }
    }
  
    handle(onResolved) {
      if (this.state == 'pending') {
        this.deferred = onResolved;
      } else {
        onResolved(this.value);
      }
    }
  
    then(onResolved) {
      this.handle(onResolved);
    }
  }
  
  const log = v =&gt; {
    console.log(v);
  };
  const myFun = () =&gt; {
    return new APromise(resolve =&gt; {
      resolve('Hello World');
    });
  };
  
  myFun().then(log);
  </code></pre>
  
  <p>Error -</p>
  
  <pre><code>this.value = newValue;
             ^
  TypeError: Cannot set property 'value' of undefined
  </code></pre>
  
  <p>But I'm already inside my es6 class, why is it saying this to be undefined? I tried debugging and looking for same problem in google but I can't find a similar one :(</p>