--- title: Notification.data slug: Web/API/notification/data translation_of: Web/API/Notification/data ---

{{APIRef("Web Notifications")}}

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

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

{{AvailableInWorkers}}

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

https://dassur.ma/things/deep-copy/ 

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

function structuralClone(obj) {
  return new Notification('', {data: obj, silent: true}).data;
}

Syntax 表达式

var data = Notification.data;

Value(返回值)

结构化的克隆数据

Examples 例子

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

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

Specifications

Specification Status Comment
{{SpecName('Web Notifications','#dom-notification-data','data')}} {{Spec2('Web Notifications')}} Living standard

Browser compatibility

{{ CompatibilityTable() }}

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari
Basic support {{CompatChrome(44)}} {{CompatVersionUnknown}} {{ CompatNo() }} {{ CompatNo() }} {{CompatOpera(34)}} {{ CompatNo() }}
Available in workers {{CompatChrome(44)}} {{CompatUnknown}} {{CompatGeckoDesktop("41.0")}} {{CompatUnknown}} {{CompatOpera(34)}} {{CompatUnknown}}
Secure contexts only {{CompatChrome(62)}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatOpera(49)}} {{CompatUnknown}}
Feature Android Webview Chrome for Android Edge Firefox Mobile (Gecko) Firefox OS IE Mobile Opera Mobile Safari Mobile
Basic support {{ CompatNo() }} {{CompatChrome(44)}} {{CompatVersionUnknown}} {{ CompatNo() }} {{ CompatNo() }} {{ CompatNo() }} {{CompatOperaMobile(34)}} {{ CompatNo() }}
Available in workers {{ CompatNo() }} {{CompatChrome(44)}} {{CompatUnknown}} {{CompatGeckoMobile(41.0)}} {{CompatUnknown}} {{CompatUnknown}} {{CompatOperaMobile(34)}} {{CompatUnknown}}
Secure contexts only {{ CompatNo() }} {{CompatChrome(62)}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatOperaMobile(49)}} {{CompatUnknown}}

See also