インスタンス化して文字出力:jsのクラス(オブジェクト指向)

  1. <!DOCTYPE html>
  2. <html lang="ja">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>インスタンス化して文字出力:jsのクラス(オブジェクト指向)</title>
  6. </head>
  7. <body>
  8. <h1>インスタンス化して文字出力:jsのクラス(オブジェクト指向)</h1>
  9. <script type="text/javascript">
  10.   // 単純なクラスを定義
  11.   var SimpleObjects = function(soT)
  12.   {
  13.     // プロパティ
  14.     this.soText = soT;
  15.     
  16.     // メソッド
  17.     this.soOutput = function()
  18.     {
  19.       document.write(this.soText);
  20.     }
  21.   };
  22.   // インスタンス化
  23.   var runSimpleObject = new SimpleObjects("newでインスタンス作成");
  24.   
  25.   // 作成したインスタンス内のsoOutputメソッドを実行
  26.   runSimpleObject.soOutput();
  27. </script>
  28. <div style="font-size:10pt;text-align:right;margin-top:0.5em;">
  29. <a href="//tips.recatnap.info/" target="_top">PCスキルの小技・忘却防止メモ</a> -
  30. <a href="//tips.recatnap.info/wiki/" target="_top">PCスキルの小技・忘却防止メモのまとめ(wiki)</a>
  31. </div>
  32. <div style="font-size:10pt;text-align:center;margin-top:0.5em;padding:0.5em;border-top:1px solid #ccc;">
  33. Copyright &copy; 2009 by PCスキルの小技・忘却防止メモ. All rights reserved.
  34. </div>
  35. </body>
  36. </html>