JavaScript中toString()方法的使用详解


JavaScript Boolean.toSource()方法返回表示对象的源代码的字符串。

注意:此方法不会在Internet Explorer中运行。
语法

boolean.toSource()

下面是参数的详细信息:

NA

返回值

返回表示对象的源代码的字符串。
例子:

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

简介JavaScript中valueOf()方法的使用
JavaScript的Boolean.valueOf()方法返回指定Boolean对象的原始值.语法boolean.valueOf()下面是参数的详细信息:NA返回值:返回指定Boolean对象的原始值。例子:htmlheadt

JavaScript中length属性的使用方法
此属性返回字符串中的字符数。语法string.length下面是参数的详细信息:Astring返回值:返回字符串中的字符数。例子:htmlheadtitleJavaScriptStringlengthProperty/tit

简介JavaScript中charAt()方法的使用
这个方法返回从指定索引的字符。字符串中的字符进行索引从左向右。第一个字符的索引是0,并且在一个叫stringName字符串的最后一个字符的索引是string