描述
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());
</script>
</body>
</html>
输出
({title:"Perl", publisher:"Leo Inc", price:200})