Help us understand the problem. What is going on with this article?

asp.net coreで書く細かいjavascript module の記法

More than 1 year has passed since last update.

asp.net coreと言えど javascript コードを書くのに1個のファイルにごちゃごちゃと色んなものを混ぜたくはないので、適当なモジュールに分割したい。

モジュールの記述

モジュール "Mod" を_mod.js に書く。

/**
* 何か機能を提供するモジュール
*/
var Mod = Mod || (function(){
   var privateVariable = 1;

    var o = {
        /**
        * 何かを実行する関数
        */
        method: function(){
            return privateVariable;
        }
    }
    return o;
})();

bundle

拡張機能 Bundler & Minifier をインストールしておき、 bundleconfig.jsonを書く

[
  {
    "outputFileName": "wwwroot/js/global.js",
    "inputFiles": [
      "wwwroot/js/src/_mod.js",
    ],
    "minify": {
      "enabled": true,
      "renameLocals": true
    },
    "sourceMap": false
  }
]

これで bundle を実行すると wwwroot/js/global.js が生成されるので、 _Layoutあたりで参照しておけば良い

jsdoc

匿名関数に必要なものを入れつつ jsdocが有効になるやり方を探っていたけど、モジュールの記述で書いたような var Foo = Foo || (function(){})(); みたいな書き方に落ち着きつつある。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした