Search code examples
javascriptes6-classprototypal-inheritance

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.


Solution

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