Backbonejs-model-extend

提供:Dev Guides
移動先:案内検索

BackboneJS-モデル拡張

説明

独自のバックボーンモデルを作成しながら、 backbone.Model クラスを拡張するために使用されます。

構文

Backbone.Model.extend(properties, [classProperties])

パラメーター

  • properties -Modelクラスのインスタンスプロパティを提供します。
  • classProperties -クラスのプロパティはコンストラクタ関数に添付されます。

<!DOCTYPE html>
<html>

   <head>
      <title> Model Example</title>
      <script src = "https://code.jquery.com/jquery-2.1.3.min.js"
         type = "text/javascript"></script>

      <script src = "https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.2/underscore-min.js"
         type = "text/javascript"></script>

      <script src = "https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.1.2/backbone-min.js"
         type = "text/javascript"></script>

      <script type = "text/javascript">
         MyModel = Backbone.Model.extend ({
            initialize: function() {
               document.write("Welcome to finddevguides..");
            }
         });
         var mymodel = new MyModel;
      </script>

   </head>
   <body></body>
</html>

出力

上記のコードがどのように機能するかを確認するために、次の手順を実行してみましょう-

  • 上記のコードを extend ファイルに保存します。
  • このHTMLファイルをブラウザーで開きます。