是否有一种单行或更优雅的方式在箭头函数中返回新创建的对象?

Is there a one-line or more elegant way of returning a newly created object in an arrow function?

我想把这种功能写在一行中,或者其他更优雅的方式。 我首先用一些 props 构造了一个 class,然后在其中调用并 return 一个 promise 函数。

 createSomeClass = (props) => {
    this._newClass = new ClassObject(props);
    return this._newClass.callPromise();
  }

嗯,只有一行:

  createSomeClass = (props) => (this._newClass = new ClassObject(props)).somePromise()

但你为什么要关心?只是让它成为一个单行代码并不能使代码变得更好,只是坚持你的代码并继续解决相关问题(例如 你是否需要这个方法?它必须是一个方法吗? )