javascript full stack development practice-web-10

javascript full stack development practice-web-10

The dead program is not lying at the end of the webpack part, we use assert instead of the previous throw Error. First of all, we are in the previous code ActionData:

export default class ActionData {
 //
  constructor(type, lineWidth, strokeStyle) {
    this._type = type;
    this._lineWidth = lineWidth;
    this._strokeStyle = strokeStyle;
  }
 //
  draw(ctx) { throw new Error('draw not implemented'); }
}
 

In the draw method implementation, we directly throw an exception. This shows that if it shouldn't run to here. Because this method needs to be implemented by subclasses. If the subclass is not implemented, this exception will occur. In this case, we should stop the program as soon as possible for a situation that we think shouldn't happen, instead of ignoring this kind of error and letting the program run erroneously. Otherwise, we may not be able to find the error for a long time, or it may cause the error to take a long time to find the cause. Before, we directly throw an exception. Now we can switch to a better way: assert.

import assert from 'assert';

export default class ActionData {
 //
  constructor(type, lineWidth, strokeStyle) {
    this._type = type;
    this._lineWidth = lineWidth;
    this._strokeStyle = strokeStyle;
  }
 //
  draw(ctx) { assert(false, 'draw not implemented'); }
}

 

From next time, we will start to use react to transform our programs and make our programs more beautiful.