Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return JavaScript class value instead of object reference (in ES6)

Tags:

I'm looking to create a class so that it will return a value instead of the class object in ES6.

It's pretty much the same question as this but in ES6. This touches on it a little bit, but you still have to explicitly call a property.

I want to do something like:

class Foo {
  constructor(value) {
    this.value = value;  // returns an object other than *this*.
  }
}    

var foo = new Foo(4);
console.log(foo) // 4

But currently it returns {value: 4}.