ES6 and this with defineProperties

by Kikketer

JavaScript

class AwesomeClass {
  constructor() {
  	let that = this; // Here's the challenge, get rid of "that"
		Object.defineProperty(this, 'detail', {
    	get: function() {
	      return this.value;
      },
      set: function(val) {
      	this.value = val;
       	// I want to run a method on the class now...
        that.someMethod();
      }
    });
  }
  
  someMethod() {
  	// Do something in response to this.detail changing
  }
}