aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/notification/data/index.html
blob: b7426d601e785c83b004be2f0eaa72d821615f21 (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
---
title: Notification.data
slug: Web/API/notification/data
translation_of: Web/API/Notification/data
---
<p>{{APIRef("Web Notifications")}}</p>

<p><code>data</code> 只读属性是 {{domxref("Notification")}} 的接口,当它作为构造函数的option可选项之一时,返回结构化的Notification的data数据。</p>

<p>当你创建Notification时,notification使用的数据可以使任意类型。</p>

<p>{{AvailableInWorkers}}</p>

<p>附加语法糖:关于克隆对象的速度研究。</p>

<p>https://dassur.ma/things/deep-copy/ </p>

<p>博客作者认为目前(参考)最快的object克隆、复制方式。</p>

<pre style="color: #f8f8f2; background-color: #272822;"><code class="language-js"><span style="color: #66d9ef;">function</span> <span style="color: #a6e22e;">structuralClone</span>(<span style="color: #a6e22e;">obj</span>) {
  <span style="color: #66d9ef;">return</span> <span style="color: #66d9ef;">new</span> <span style="color: #a6e22e;">Notification</span>(<span style="color: #e6db74;">''</span>, {<span style="color: #a6e22e;">data</span><span style="color: #f92672;">:</span> <span style="color: #a6e22e;">obj</span>, <span style="color: #a6e22e;">silent</span><span style="color: #f92672;">:</span> <span style="color: #66d9ef;">true</span>}).<span style="color: #a6e22e;">data</span>;
}</code></pre>

<h2 id="Syntax" name="Syntax">Syntax 表达式</h2>

<pre class="eval">var <em>data</em> = Notification.data;
</pre>

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

<p>结构化的克隆数据</p>

<h2 id="Examples_例子">Examples 例子</h2>

<p>产生一个 notification; <code>简单的options</code> 作为构造参数, 将会触发以option为构造参数的 <code>Notification()</code> .</p>

<pre class="brush: js">var options = {
  body: 'Do you like my body?',
  data: 'I like peas.'
}

var n = new Notification('Test notification',options);

n.data // should return 'I like peas.'</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('Web Notifications','#dom-notification-data','data')}}</td>
   <td>{{Spec2('Web Notifications')}}</td>
   <td>Living standard</td>
  </tr>
 </tbody>
</table>

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

<p>{{ CompatibilityTable() }}</p>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Edge</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatChrome(44)}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{ CompatNo() }}</td>
   <td>{{ CompatNo() }}</td>
   <td>{{CompatOpera(34)}}</td>
   <td>{{ CompatNo() }}</td>
  </tr>
  <tr>
   <td>Available in workers</td>
   <td>{{CompatChrome(44)}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatGeckoDesktop("41.0")}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatOpera(34)}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
  <tr>
   <td>Secure contexts only</td>
   <td>{{CompatChrome(62)}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatOpera(49)}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android Webview</th>
   <th>Chrome for Android</th>
   <th>Edge</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>Firefox OS</th>
   <th>IE Mobile</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{ CompatNo() }}</td>
   <td>{{CompatChrome(44)}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{ CompatNo() }}</td>
   <td>{{ CompatNo() }}</td>
   <td>{{ CompatNo() }}</td>
   <td>{{CompatOperaMobile(34)}}</td>
   <td>{{ CompatNo() }}</td>
  </tr>
  <tr>
   <td>Available in workers</td>
   <td>{{ CompatNo() }}</td>
   <td>{{CompatChrome(44)}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatGeckoMobile(41.0)}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatOperaMobile(34)}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
  <tr>
   <td>Secure contexts only</td>
   <td>{{ CompatNo() }}</td>
   <td>{{CompatChrome(62)}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatOperaMobile(49)}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<h2 id="See_also">See also</h2>

<ul>
 <li><a href="/en-US/docs/Web/API/Notifications_API/Using_the_Notifications_API">Using the Notifications API</a></li>
</ul>