标签:
In constructor, you can call parent‘s constuctor() method by supert();
class ShoppingCart { constructor(userId){ this.userId = userId; this.products = []; } addProducts(product){ this.products.push(product); } calculate(){ super.calculate(); } } class ForumShoppingCart extends ShoppingCart { constructor(userId){ super(userId); } calculate(){ let partialCost = // call parent class `calculate` method here return partialCost - _calculateDiscount(); } _calculateDiscount(){ //... complex math } }
标签:
原文地址:http://www.cnblogs.com/Answer1215/p/5131518.html