Es6-boolean-method-tosource

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

ES6-toSource()

Javascript boolean * toSource()*メソッドは、オブジェクトのソースコードを表す文字列を返します。

注意-この方法は、すべてのブラウザと互換性があるわけではありません。

以下は同じ構文です。

boolean.toSource()

<html>
   <head>
      <title>JavaScript toSource() Method</title>
   </head>
   <body>
      <script type="text/javascript">
         function book(title, publisher, price) {
            this.title = title;
            this.publisher = publisher;
            this.price = price;
         }
         var newBook = new book("Perl","Leo Inc",200);
         document.write("newBook.toSource() is : "+ newBook.toSource());
      </script>
   </body>
</html>

上記のコードが正常に実行されると、次の出力が表示されます。

({title:"Perl", publisher:"Leo Inc", price:200})