Skip to content

Instantly share code, notes, and snippets.

@triacontane
Created April 8, 2018 16:19
Show Gist options
  • Select an option

  • Save triacontane/ad78514de6d9a412591abbfcff602566 to your computer and use it in GitHub Desktop.

Select an option

Save triacontane/ad78514de6d9a412591abbfcff602566 to your computer and use it in GitHub Desktop.
定数(もどき)を定義するサンプル
(function() {
'use strict';
var constX = 1;
Game_CharacterBase._constY = 1;
var _Game_CharacterBase_refreshBushDepth = Game_CharacterBase.prototype.refreshBushDepth;
Game_CharacterBase.prototype.refreshBushDepth = function() {
_Game_CharacterBase_refreshBushDepth.apply(this, arguments);
console.log(constX); // 1
console.log(Game_CharacterBase._constY); // 2
};
})();
@triacontane
Copy link
Author

即時関数の中で定義した「constX」は関数内のどこからでも参照できます。(入れ子で定義した関数含む)
また、コアスクリプトでは定数は「Game_CharacterBase._constY」のような書き方をされることが多いようです。

※ JavaScript(ES5)には、ちゃんとした定数の定義方法がないのであくまで変数を定数のように扱っているだけです。

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