Skip to content

Commit 9523e17

Browse files
committed
docs(stdlib): fix toLocaleString()
1 parent 68ee16b commit 9523e17

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

docs/stdlib/object.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,25 @@ obj.toString(obj) // "[object Object]"
401401
obj.toLocaleString(obj) // "[object Object]"
402402
```
403403

404-
这个方法的主要作用是留出一个接口,让各种不同的对象实现自己版本的`toLocaleString`,用来返回针对某些地域的特定的值。目前,主要有三个对象自定义了`toLocaleString`方法。
404+
这个方法的主要作用是留出一个接口,让各种不同的对象实现自己版本的`toLocaleString`,用来返回针对某些地域的特定的值。
405+
406+
```javascript
407+
var person = {
408+
toString(): function () {
409+
return 'Henry Norman Bethune';
410+
},
411+
toLocaleString(): function () {
412+
return '白求恩';
413+
}
414+
};
415+
416+
person.toString() // Henry Norman Bethune
417+
person.toLocaleString() // 白求恩
418+
```
419+
420+
上面代码中,`toString()`方法返回对象的一般字符串形式,`toLocaleString()`方法返回本地的字符串形式。
421+
422+
目前,主要有三个对象自定义了`toLocaleString`方法。
405423

406424
- Array.prototype.toLocaleString()
407425
- Number.prototype.toLocaleString()

0 commit comments

Comments
 (0)