🤖

クラスの書き方

2021/12/29に公開

CoffeeScriptが生成したJavaScriptコードを参考にした。

var Hoge;
Hoge = (function () {
  var items;

  function Hoge(items) {
    this.items = items;
  }

  Hoge.classMethod = function () {
    console.log("classMethod");
  };

  Hoge.prototype.instanceMethod = function () {
    console.log("instanceMethod");
  };

  return Hoge;

})();
Hoge.classMethod();

var obj = new Hoge({obj: 'object'});
obj.instanceMethod();

Discussion