aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/javascript/reference/global_objects/boolean/valueof/index.html
blob: 62137bbdf685bbe871df73c81dd306bd8d872efd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
---
title: Boolean.prototype.valueOf()
slug: Web/JavaScript/Reference/Global_Objects/Boolean/valueOf
tags:
  - Boolean
  - JavaScript
  - Method
  - Prototype
translation_of: Web/JavaScript/Reference/Global_Objects/Boolean/valueOf
---
<div>{{JSRef}}</div>

<p><code><strong>valueOf()</strong></code> 方法返回一个{{jsxref("Boolean")}}对象的原始值。</p>

<div>{{EmbedInteractiveExample("pages/js/boolean-valueof.html")}}</div>



<h2 id="Syntax">语法</h2>

<pre class="syntaxbox"><code><var>bool</var>.valueOf()</code></pre>

<h3 id="返回值">返回值</h3>

<p>给定{{jsxref("Boolean")}}对象的原始值</p>

<h2 id="Description">描述</h2>

<p>{{jsxref("Boolean")}}的 <code>valueOf</code> 方法返回一个{{jsxref("Boolean")}}对象或{{jsxref("Boolean")}}字面量的原始值作为布尔数据类型。</p>

<p>该方法通常在 JavaScript 内部调用,而不是在代码中显式调用。</p>

<h2 id="Examples">示例</h2>

<h3 id="Example:_Using_valueOf">使用 <code>valueOf</code></h3>

<pre class="brush: js">x = new Boolean();
myVar = x.valueOf()      // assigns false to myVar
</pre>

<h2 id="规范">规范</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>{{SpecName('ES1')}}</td>
   <td>{{Spec2('ES1')}}</td>
   <td>Initial definition. Implemented in JavaScript 1.1.</td>
  </tr>
  <tr>
   <td>{{SpecName('ES5.1', '#sec-15.6.4.3', 'Boolean.prototype.valueOf')}}</td>
   <td>{{Spec2('ES5.1')}}</td>
   <td> </td>
  </tr>
  <tr>
   <td>{{SpecName('ES6', '#sec-boolean.prototype.valueof', 'Boolean.prototype.valueOf')}}</td>
   <td>{{Spec2('ES6')}}</td>
   <td> </td>
  </tr>
  <tr>
   <td>{{SpecName('ESDraft', '#sec-boolean.prototype.valueof', 'Boolean.prototype.valueOf')}}</td>
   <td>{{Spec2('ESDraft')}}</td>
   <td> </td>
  </tr>
 </tbody>
</table>

<h2 id="浏览器兼容">浏览器兼容</h2>

<p>{{Compat("javascript.builtins.Boolean.valueOf")}}</p>

<h2 id="See_Also">相关链接</h2>

<ul>
 <li>{{jsxref("Object.prototype.valueOf()")}}</li>
</ul>