Created
April 8, 2018 16:19
-
-
Save triacontane/ad78514de6d9a412591abbfcff602566 to your computer and use it in GitHub Desktop.
定数(もどき)を定義するサンプル
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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 | |
| }; | |
| })(); |
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
ok