开发学院

您的位置:首页>教程>正文

教程正文

ES6 Boolean方法toSource()

ES6 Boolean方法toSource()

  JavaScript布尔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})