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

翻译正在进行中。

概览

 String.prototype 这个属性表示了 String 其原型对象。

String.prototype 属性的属性特性:
writable false
enumerable false
configurable false

描述

所有 String 的实例都继承自 String.prototype. 任何String.prototype上的改变都会影响到所有的String实例。

属性

String.prototype.constructor
用于创造对象的原型对象的特定的函数。
String.prototype.length
返回了字符串的长度。
N
Used to access the character in the Nth position where N is a positive integer between 0 and one less than the value of length. 这些属性都是“只读”性质,不能编辑。
Properties inherited from Object:

方法

跟HTML无关的方法

String.prototype.charAt()
返回字符的特定位置。
String.prototype.charCodeAt()
返回表示给定索引的字符的Unicode的值。
String.prototype.codePointAt()
返回使用UTF-16编码的给定位置的值的非负整数。
String.prototype.concat()
连接两个字符串文本,并返回一个新的字符串。
String.prototype.contains()
判断一个字符串里是否包含其他字符串。
String.prototype.endsWith()
判断一个字符串的结尾是否包含其他字符串中的字符。
String.prototype.indexOf()
从字符串对象中返回首个被发现的给定值的索引值,如果没有找到则返回-1。
String.prototype.lastIndexOf()
从字符串对象中返回最后一个被发现的给定值的索引值,如果没有找到则返回-1。
String.prototype.localeCompare()
Returns a number indicating whether a reference string comes before or after or is the same as the given string in sort order.
String.prototype.match()
使用正则表达式与字符串相比较。
String.prototype.normalize()
返回调用字符串值的Unicode标准化形式。
String.prototype.quote()
Wraps the string in double quotes (""").
String.prototype.repeat()
返回指定重复次数的由元素组成的字符串对象。
String.prototype.replace()
被用来在正则表达式和字符串直接比较,然后用新的子串来替换被匹配的子串。
String.prototype.search()
对正则表达式和指定字符串进行匹配搜索,返回第一个出现的匹配项的下标。
String.prototype.slice()
摘取一个字符串区域,返回一个新的字符串。
String.prototype.split()
通过分离字符串成字串,将字符串对象分割成字符串数组。
String.prototype.startsWith()
判断字符串的起始位置是否匹配其他字符串中的字符。
String.prototype.substr()
Returns the characters in a string beginning at the specified location through the specified number of characters.
String.prototype.substring()
返回在字符串中指定另个下标之间的字符。
String.prototype.toLocaleLowerCase()
根据当前区域设置,将符串中的字符转换成小写。对于大多数语言来说,toLowerCase的返回值是一致的。
String.prototype.toLocaleUpperCase()
根据当前区域设置,将字符串中的字符转换成大写,对于大多数语言来说,toUpperCase的返回值是一致的。
String.prototype.toLowerCase()
将字符串转换成小写并返回。
String.prototype.toSource()
Returns an object literal representing the specified object; you can use this value to create a new object. Overrides the Object.prototype.toSource method.
String.prototype.toString()
返回用字符串表示的特定对象。重写 Object.prototype.toString 方法。
String.prototype.toUpperCase()
将字符串转换成大写并返回。
String.prototype.trim()
从字符串的开始和结尾去除空格。参照部分 ECMAScript 5 标准。
String.prototype.trimLeft()
从字符串的左侧去除空格。
String.prototype.trimRight()
从字符串的右侧去除空格。
String.prototype.valueOf()
返回特定对象的原始值。重写 Object.prototype.valueOf 方法。

HTML wrapper methods

下面的方法被限制使用,因为只对可用的HTML表情和属性提供部分支持。

String.prototype.anchor()
<a name="name"> (hypertext target)
String.prototype.big()
<big>
String.prototype.blink()
<blink>
String.prototype.bold()
<b>
String.prototype.fixed()
<tt>
String.prototype.fontcolor()
<font color="color">
String.prototype.fontsize()
<font size="size">
String.prototype.italics()
<i>
String.prototype.link()
<a href="url"> (link to URL)
String.prototype.small()
<small>
String.prototype.strike()
<strike>
String.prototype.sub()
<sub>
String.prototype.sup()
<sup>

Specifications

Specification Status Comment
ECMAScript 1st Edition. Standard Initial definition.
ECMAScript 5.1 (ECMA-262)
String.prototype
Standard  
ECMAScript 2015 (6th Edition, ECMA-262)
String.prototype
Standard  

浏览器兼容性

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)

更多

文档标签和贡献者

 此页面的贡献者: terrycafe520, qianjiahao, paddingme, teoli, ziyunfei
 最后编辑者: terrycafe520,