★ 首先,构造方法constructor是不能被继承,同样的也就不能被重写了,但是可以它被重载。
通过在子类的构造方法中的开头添上super([参数]),以表明子类构造之前先构造父类。
父类
import Coin from './coin';
import PaySDK from './pay/sdk';
class CashierForm {
constructor(props) {
this.$form = $(props.element);
this.$priceList = this.$form.find('#order-center-price-list');
this.validator = this.$form.validate();
this.initEvent();
this.initCoin();
this.paySdk = new PaySDK();
this.paySdk.checkOrderStatus();
}
...
...
子类方法重写
import PaySDK from './pay/sdk';
import BaseFrom from '../../../../../../app/Resources/static-src/app/js/cashier/form';
class Form extends BaseFrom {
constructor(props) {
super(props);
this.paySdk = new PaySDK();
this.paySdk.checkOrderStatus();
}
...
...
网友评论