aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/performanceentry/name/index.html
blob: a12b1c4c67fc93c391bbdb7ce7742b3a690b9a41 (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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
---
title: PerformanceEntry.name
slug: Web/API/PerformanceEntry/name
translation_of: Web/API/PerformanceEntry/name
---
<div>{{APIRef("Performance Timeline API")}}</div>

<p><span class="seoSummary"><strong><code>name 是</code></strong> {{domxref("PerformanceEntry")}} 接口的属性,此属性的返回值是 {{domxref("PerformanceEntry.entryType")}} 的返回值的一个补充,例如entry.entryType="navigation",entry.name="document". 这是一个只读属性.</span></p>

<h2 id="Syntax" name="Syntax">Syntax</h2>

<pre class="syntaxbox">var<em> name</em> = <em>entry</em>.name;
</pre>

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

<p>返回值取决于<code>PerformanceEntry</code> 对象的 subtype和{{domxref("PerformanceEntry.entryType")}}的值, 如下表所示.</p>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Value</th>
   <th scope="col">Subtype</th>
   <th scope="col">entryType values</th>
   <th scope="col">Description</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{domxref("URL")}}</td>
   <td>{{domxref('PerformanceFrameTiming')}}, {{domxref('PerformanceNavigationTiming')}}</td>
   <td><code>frame</code>, <code>navigation</code></td>
   <td>The document's address.</td>
  </tr>
  <tr>
   <td>{{domxref("URL")}}</td>
   <td>{{domxref('PerformanceResourceTiming')}}</td>
   <td><code>resource</code></td>
   <td>The resolved URL of the requested resource. This value doesn't change even if the request is redirected.</td>
  </tr>
  <tr>
   <td>{{domxref("DOMString")}}</td>
   <td>{{domxref('PerformanceMark')}}</td>
   <td><code>mark</code></td>
   <td>The name used when the mark was created by calling {{domxref("Performance.mark","performance.mark()")}}.</td>
  </tr>
  <tr>
   <td>{{domxref("DOMString")}}</td>
   <td>{{domxref('PerformanceMeasure')}}</td>
   <td><code>measure</code></td>
   <td>name used when the measure was created by calling {{domxref("Performance.measure","performance.measure()")}}.</td>
  </tr>
  <tr>
   <td>{{domxref("DOMString")}}</td>
   <td>{{domxref('PerformancePaintTiming')}}</td>
   <td><code>paint</code></td>
   <td>Either <code>'first-paint'</code> or <code>'first-contentful-paint'</code>.</td>
  </tr>
 </tbody>
</table>

<h2 id="用例">用例</h2>

<p>下面的例子是 <code>name</code> 属性的用法.</p>

<pre class="brush: js">function run_PerformanceEntry() {
  log("PerformanceEntry support ...");

  if (performance.mark === undefined) {
    log("... performance.mark Not supported");
    return;
  }

  // Create some performance entries via the mark() method
  performance.mark("Begin");
  do_work(50000);
  performance.mark("End");

  // Use getEntries() to iterate through the each entry
  var p = performance.getEntries();
  for (var i=0; i &lt; p.length; i++) {
    log("Entry[" + i + "]");
    check_PerformanceEntry(p[i]);
  }
}
  //
  //例如上面p中一个entry p[0] = {
  //  "name": "document",
  //  "entryType": "navigation",
  //  "startTime": 0,
  //  "duration": 3611.26,
  //  "initiatorType": "navigation",
  //  "nextHopProtocol": "http/1.1",
  //  "workerStart": 0,
  //  "redirectStart": 0,
  //  "redirectEnd": 0,
  //  "fetchStart": 0.32,
  //  "domainLookupStart": 17.64,
  //  "domainLookupEnd": 17.78,
  //  "connectStart": 17.86,
  //  "connectEnd": 18.1,
  //  "secureConnectionStart": 0,
  //  "requestStart": 18.3,
  //  "responseStart": 294.06,
  //  "responseEnd": 1610.3600000000001,
  //  "transferSize": 97683,
  //  "encodedBodySize": 97112,
  //  "decodedBodySize": 97112,
  //  "unloadEventStart": 1614.8372840721554,
  //  "unloadEventEnd": 1619.1600105887128,
  //  "domInteractive": 3110.767514889843,
  //  "domContentLoadedEventStart": 3125.859851800787,
  //  "domContentLoadedEventEnd": 3438.5779820633365,
  //  "domComplete": 3609.999662153349,
  //  "loadEventStart": 3610.017623620869,
  //  "loadEventEnd": 3611.2672285754975,
  //  "type": "reload",
  //  "redirectCount": 0
  //}

  //下面的函数check_PerformanceEntry的参数obj就是上面的p[0]
  //
function check_PerformanceEntry(obj) {
  var properties = ["name", "entryType", "startTime", "duration"];
  var methods = ["toJSON"];

  for (var i=0; i &lt; properties.length; i++) {
    // check each property
    var supported = properties[i] in obj;
    if (supported)
      log("..." + properties[i] + " = " + obj[properties[i]]);
    else
      log("..." + properties[i] + " = Not supported");
  }
  for (var i=0; i &lt; methods.length; i++) {
    // check each method
    var supported = typeof obj[methods[i]] == "function";
    if (supported) {
      var js = obj[methods[i]]();
      log("..." + methods[i] + "() = " + JSON.stringify(js));
    } else {
      log("..." + methods[i] + " = Not supported");
    }
  }
}
</pre>

<h2 id="Specifications">Specifications</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('Performance Timeline Level 2', '#dom-performanceentry-name', 'name')}}</td>
   <td>{{Spec2('Performance Timeline Level 2')}}</td>
   <td> </td>
  </tr>
  <tr>
   <td>{{SpecName('Performance Timeline', '#dom-performanceentry-name', 'name')}}</td>
   <td>{{Spec2('Performance Timeline')}}</td>
   <td>Initial definition.</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<div>
<div>


<p>{{Compat("api.PerformanceEntry.name")}}</p>
</div>
</div>