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

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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"; } } const bags = new Bags({type: "raffia"}); bags bags.discount();
class Bags {
  constructor(options) {
    this.type = options.type;
  }
  discount(){
    return "No discounts";
  }

}

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

 

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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();
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();
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();

 

 

 

 

  • URLをコピーしました!

Writer

TIERは、Global、DX、HRの3軸により 大手企業から中小企業、民間企業から行政まで、海外展開に必要なサービスをワンストップで支援しております。海外マーケティングセールスからデジタルマーケティング、多言語サイトや越境ECサイト制作等の海外向けクリエイティブ制作、グローバル人材採用支援まで幅広く対応しております。お気軽にお問い合わせください。

目次