Home / JavaScript/Vue.js / JavaScriptメモ:ES6 Class(承継)サンプルコード

JavaScriptメモ:ES6 Class(承継)サンプルコード

class Bags {
  constructor(options) {
    this.type = options.type;
  }
  discount(){
    return "No discounts";
  }

}

const bags = new Bags({type: "raffia"});
bags
bags.discount();

 

class Bags {
  constructor(options) {
    this.type = options.type;
  }
  discount(){
    return "No discounts";
  }

}


class Gnome extends Bags {
  constructor(options) {
    super(options);
    this.color = options.color;
  }
  country() {
    return "Singapore";

  }
}

const gnome = new Gnome({color: "red", type: "leather"});
gnome;
gnome.country();
gnome.discount();

 

 

 

 

Check Also

Pythonメモ:関数定義のサンプルコード

#関数定義 def greet …