Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

String.prototype.toString()

概述

toString() 方法返回指定对象的字符串形式。

语法

str.toString()

描述

String 对象覆盖了Object 对象的 toString 方法;并没有继承 Object.toString()。对于 String 对象,toString 方法返回该对象的字符串形式,和 String.prototype.valueOf() 方法返回值一样。

示例

例子:使用 toString

下例输出一个字符串对象(String object)的字符串值:

var x = new String("Hello world");

alert(x.toString())      // 输出 "Hello world"

规范

Specification Status Comment
ECMAScript 1st Edition. Standard Initial definition.
Implemented in JavaScript 1.1.
ECMAScript 5.1 (ECMA-262)
String.prototype.toString
Standard  
ECMAScript 6 (ECMA-262)
String.prototype.toString
Release Candidate  

浏览器兼容性

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support (Yes) (Yes) (Yes) (Yes) (Yes)
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support (Yes) (Yes) (Yes) (Yes) (Yes) (Yes)

相关链接

文档标签和贡献者

 此页面的贡献者: AlexChao
 最后编辑者: AlexChao,