aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/notification/data/index.html
blob: d4d3c44a557d355abe5e2a05e9c93f64a02efcfa (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
---
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>

{{Compat("api.Notification.data")}}

<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>