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})
廣告