サイト内検索

Array メソッド一覧

スポンサー

ホーム > Array > toSource

toSource

オブジェクトの内容を文字列で返します.

シンタックス

object.toSource()

解説

toSourceメソッドはオブジェクトの内容を文字列で返します. なお,toSourceメソッドはInternet Explorerではサポートされていません.

サンプルコード

以下にtoSourceメソッドを使用して,配列・オブジェクト・関数の内容を取得するサンプルコードを示します.

<html>
  <head>
    <title>toSourceメソッドのサンプルコード</title>
  </head>
  <body>
    <script type="text/javascript" language="javascript">
      /* 配列 */
      var ary = new Array("Snoopy","Charlie","Woodstock");
      document.write(ary + "<br />");
      document.write(ary.toSource() + "<br />");
      document.write("<br />");

      /* オブジェクト */
      var obj = {x:2, y:3, z:1};
      document.write(obj + "<br />");
      document.write(obj.toSource() + "<br />");
      document.write("<br />");

      /* 関数 */
      function power(x) {
        return x * x;
      }
      document.write(power(1) + "<br />");
      document.write(power.toSource() + "<br />");
    </script>
  </body>
</html>

実行例

サンプルコードの実行結果は以下のようになります.

Snoopy,Charlie,Woodstock
["Snoopy", "Charlie", "Woodstock"]

[object Object]
({x:2, y:3, z:1})

1
function power(x) {return x * x;}

スポンサード リンク

inserted by FC2 system