1

RequireJs の使い方について質問があります。私たちのアプリは近い機能で大きく成長するはずなので、主要な問題は、プロジェクトに関与する開発者が従うスケルトンを準備することです。

RequireJS でこの種のラッパーを試しました (OOP アプローチを強制しようとしています)。




        //each file will contains such a definition
            //this file should be located under: appNamespace/Client/Widget.js

            //attaching the class definition to the namespace
            with ({public : appNamespace.Client})
            {
               //using a Class defined in the file: appNamespace/DomainModel/DataTable.js
               var dt = using('appNamespace.DomainModel.DataTable');

               //Class definition
               public.Widget = function(iName)
               {
                    //private variable
                    var dSort = new dt.SortableTable();

                    this.Draw = function(iRegion)
                    {
                      //public method implementation           
                    }
               }
            }
    

または、自然な RequireJS モデルのような構造を使用することもできます。

<pre><code>
//this module definition should be located in the file: appNamespace/Client/Widget.js
define('appNamespace/DomainModel/DataTable', function(dt)
{
     function Widget(iName)
     {
        //private variable
        var dSort = new dt.SortableTable();

        this.Draw = function(iRegion)
        {
            //public method implementation           
        }
     }

     return Widget;
})

次の理由から、最初の例をお勧めします。

    1. 開発者はより OOP スタイルでスクリプトを書く必要があります。
    2. C# や Java の表記に似ているため、バックエンド コードとクライアント コードをすばやく切り替えることができます。
    3. どんなスタイルのコードでも書けるので、モデル構造が本当に好きではありません。さらに、クラスを定義するだけでは不十分です。このファイルが公開している API を定義する必要があります。これにより、そのファイルの内容とは関係のない API を実際に定義できます。

では、なぜ 2 番目の例 (自然な RequireJS モデル スタイル) を使用するのでしょうか? 私が見逃しているものはありますか?

どんな提案でも大歓迎です

4

0 に答える 0