JavaScript - toSource 方法



描述

此方法返回一個表示物件原始碼的字串。

注意 - 此方法可能與並非所有瀏覽器相容。

語法

以下是 toSource() 方法的語法。

Date.toSource ()

返回值

  • 對於內建的 Date 物件,toSource 返回一個字串 (new Date(...)),表明原始碼不可用。

  • 對於 Date 的例項,toSource 返回一個表示原始碼的字串。

示例

嘗試以下示例。

<html>   
   <head>
      <title>JavaScript toSource Method</title>
   </head>
   
   <body>      
      <script type = "text/javascript">
         var dt = new Date(1993, 6, 28, 14, 39, 7);
         document.write( "Formated Date : " + dt.toSource() ); 
      </script>      
   </body>
</html>

輸出

Formated Date : (new Date(743850547000))
javascript_date_object.htm
廣告