Skip to content

Instantly share code, notes, and snippets.

@uupaa
Last active August 22, 2016 12:48
Show Gist options
  • Save uupaa/ab7234561282aaa06b42 to your computer and use it in GitHub Desktop.
Save uupaa/ab7234561282aaa06b42 to your computer and use it in GitHub Desktop.
ES5 で Classを定義する WebModule 流のイディオム

ES5 で Classを定義する WebModule 流のイディオム。メリットは2つ

  1. getter, setter をダイレクトに記述できる
  2. ファーストビューを見るだけで I/F を把握できる
function Class() {
  this._someValue = null; // Any
  ...
}

Class.prototype = Object.create(Class, {
  constructor: { value: Class },
  method: { value: Class_method },
  someValue: {
    set: function(v) { this._someValue = v; },
    get: function()  { return this._someValue; } },
});

function Class_method() {
  ...
}

ファーストビュー

このエントリに置けるファーストビューとは「スクロールせずに見渡せる範囲」という意味です。

できるだけパッと見える場所に、必要な情報が揃っているほうが嬉しいに決まっています。

見る人の環境にも依存しますが、スクロールしまくらないと I/F も把握できない状態は避けたいですね。

実装例

参考リンク

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment