简体   繁体   中英

What would be the ES6 equivalent for this return statement?

I am refactoring from prototypal inheritance to es5 classes, but I am stumped on one line.

The original code looks like this:

define('FormRegTest', ['XmUIHandler', 'jquery'],
function (xmui, $) {
  function FormRegTest(payload) {
    this.payload = payload;
  }

  FormRegTest.prototype.startSession = function(clientContext, actionContext) {
    this._uiContainer = xmui.XmUIHandler.getContainer(clientContext);

 // lots more logic here
  }
  
  return FormRegTest;
});

My ES6 version looks like this:

export default class FormRegTest {
  constructor(payload) {
    this.payload = payload;
  }

  startSession(clientContext, actionContext) {
    this._uiContainer = xmui.XmUIHandler.getContainer(clientContext);
  }

  // lots more logic here
}

But that last line of return FormRegTest does not make sense inside of here, but I am unclear if I can just ignore that line or if I am missing something. This would be my first time refactoring from prototypal inheritance to ES6 classes.

You can ignore that return statement, calling new FormRegTest() will return the new instance of your class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM