From eca516d6e2b95c9ef8f38abe8eb8b9d2e51dc14f Mon Sep 17 00:00:00 2001 From: "Queen Vinyl Da.i'gyu-Kazotetsu" Date: Fri, 28 Jul 2023 04:14:22 -0700 Subject: [PATCH 1/3] zh-cn: Format /web/api using Prettier (part 8) --- files/zh-cn/web/api/nodelist/index.md | 37 ++++--- files/zh-cn/web/api/nodelist/keys/index.md | 4 +- files/zh-cn/web/api/nodelist/length/index.md | 2 +- files/zh-cn/web/api/nodelist/values/index.md | 2 +- .../api/notification/notification/index.md | 11 +- .../zh-cn/web/api/notificationevent/index.md | 28 ++--- .../using_the_notifications_api/index.md | 24 ++--- .../web/api/oes_vertex_array_object/index.md | 2 +- .../complete_event/index.md | 18 ++-- .../web/api/offlineaudiocontext/index.md | 44 ++++---- .../offlineaudiocontext/index.md | 4 +- files/zh-cn/web/api/offscreencanvas/index.md | 11 +- files/zh-cn/web/api/origin/index.md | 2 +- .../web/api/oscillatornode/detune/index.md | 2 +- .../web/api/oscillatornode/frequency/index.md | 2 +- files/zh-cn/web/api/oscillatornode/index.md | 2 +- .../web/api/page_visibility_api/index.md | 35 ++++-- .../web/api/pagetransitionevent/index.md | 15 ++- .../pagetransitionevent/persisted/index.md | 4 +- files/zh-cn/web/api/path2d/addpath/index.md | 13 ++- files/zh-cn/web/api/path2d/path2d/index.md | 10 +- .../api/payment_request_api/concepts/index.md | 4 +- .../performance/clearresourcetimings/index.md | 6 +- .../web/api/performance/getentries/index.md | 50 ++++++--- .../api/performance/getentriesbyname/index.md | 36 +++++-- .../api/performance/getentriesbytype/index.md | 36 +++++-- .../web/api/performance/measure/index.md | 10 +- files/zh-cn/web/api/performance/now/index.md | 2 +- .../api/performanceentry/duration/index.md | 12 +-- .../api/performanceentry/entrytype/index.md | 22 ++-- files/zh-cn/web/api/performanceentry/index.md | 9 +- .../web/api/performanceentry/name/index.md | 100 +++++++++--------- .../web/api/performanceentry/tojson/index.md | 12 +-- .../api/performancelongtasktiming/index.md | 16 +-- .../performanceobserver/disconnect/index.md | 10 +- .../web/api/performanceobserver/index.md | 6 +- .../api/performanceobserver/observe/index.md | 8 +- .../performanceobserver/index.md | 8 +- .../performanceobserver/takerecords/index.md | 6 +- .../web/api/performancepainttiming/index.md | 14 ++- files/zh-cn/web/api/permissions/index.md | 6 +- .../using_the_permissions_api/index.md | 26 +++-- .../web/api/picture-in-picture_api/index.md | 4 +- .../web/api/pictureinpicturewindow/index.md | 8 +- files/zh-cn/web/api/plugin/index.md | 8 +- files/zh-cn/web/api/pointer_events/index.md | 92 ++++++++-------- files/zh-cn/web/api/pointer_lock_api/index.md | 27 ++--- files/zh-cn/web/api/progressevent/index.md | 22 ++-- .../api/progressevent/progressevent/index.md | 4 +- .../web/api/promiserejectionevent/index.md | 4 +- .../promiserejectionevent/promise/index.md | 9 +- .../promiserejectionevent/index.md | 6 +- .../api/pushmanager/getsubscription/index.md | 59 ++++++----- files/zh-cn/web/api/pushmanager/index.md | 16 +-- files/zh-cn/web/api/pushmessagedata/index.md | 21 ++-- .../web/api/pushmessagedata/json/index.md | 2 +- files/zh-cn/web/api/queuemicrotask/index.md | 2 +- files/zh-cn/web/api/range/collapsed/index.md | 4 +- .../range/commonancestorcontainer/index.md | 4 +- .../zh-cn/web/api/range/endcontainer/index.md | 4 +- files/zh-cn/web/api/range/endoffset/index.md | 4 +- .../api/range/getboundingclientrect/index.md | 13 ++- files/zh-cn/web/api/range/range/index.md | 2 +- files/zh-cn/web/api/range/setstart/index.md | 2 +- .../web/api/range/startcontainer/index.md | 4 +- .../zh-cn/web/api/range/startoffset/index.md | 4 +- .../web/api/readablestream/cancel/index.md | 100 ++++++++++-------- .../web/api/readablestream/getreader/index.md | 12 ++- files/zh-cn/web/api/readablestream/index.md | 6 +- .../api/readablestream/pipethrough/index.md | 19 ++-- .../web/api/readablestream/pipeto/index.md | 15 +-- .../readablestream/readablestream/index.md | 8 +- .../zh-cn/web/api/readablestream/tee/index.md | 7 +- .../close/index.md | 10 +- .../enqueue/index.md | 10 +- .../error/index.md | 2 +- .../readablestreamdefaultcontroller/index.md | 8 +- .../cancel/index.md | 12 ++- .../closed/index.md | 4 +- .../readablestreamdefaultreader/read/index.md | 19 ++-- .../readablestreamdefaultreader/index.md | 10 +- .../releaselock/index.md | 2 +- .../web/api/request/arraybuffer/index.md | 10 +- files/zh-cn/web/api/request/blob/index.md | 18 ++-- files/zh-cn/web/api/request/bodyused/index.md | 8 +- files/zh-cn/web/api/request/cache/index.md | 20 ++-- files/zh-cn/web/api/request/clone/index.md | 2 +- .../web/api/request/credentials/index.md | 2 +- files/zh-cn/web/api/request/formdata/index.md | 14 +-- files/zh-cn/web/api/request/headers/index.md | 18 ++-- files/zh-cn/web/api/request/json/index.md | 14 +-- files/zh-cn/web/api/request/method/index.md | 2 +- files/zh-cn/web/api/request/mode/index.md | 2 +- files/zh-cn/web/api/request/request/index.md | 40 +++---- files/zh-cn/web/api/request/text/index.md | 10 +- files/zh-cn/web/api/request/url/index.md | 2 +- .../web/api/resize_observer_api/index.md | 4 +- .../api/resizeobserver/disconnect/index.md | 4 +- files/zh-cn/web/api/resizeobserver/index.md | 37 ++++--- .../web/api/resizeobserver/observe/index.md | 29 +++-- 100 files changed, 809 insertions(+), 667 deletions(-) diff --git a/files/zh-cn/web/api/nodelist/index.md b/files/zh-cn/web/api/nodelist/index.md index f0d81c3e16255c..983874e0c8f70a 100644 --- a/files/zh-cn/web/api/nodelist/index.md +++ b/files/zh-cn/web/api/nodelist/index.md @@ -14,10 +14,10 @@ slug: Web/API/NodeList 在一些情况下,`NodeList` 是一个实时集合,也就是说,如果文档中的节点树发生变化,`NodeList` 也会随之变化。例如,{{domxref("Node.childNodes")}} 是实时的: ```js -var parent = document.getElementById('parent'); +var parent = document.getElementById("parent"); var child_nodes = parent.childNodes; console.log(child_nodes.length); // 我们假设结果会是“2” -parent.appendChild(document.createElement('div')); +parent.appendChild(document.createElement("div")); console.log(child_nodes.length); // 但此时的输出是“3” ``` @@ -49,7 +49,7 @@ console.log(child_nodes.length); // 但此时的输出是“3” ```js for (var i = 0; i < myNodeList.length; ++i) { - var item = myNodeList[i]; // 调用 myNodeList.item(i) 是没有必要的 + var item = myNodeList[i]; // 调用 myNodeList.item(i) 是没有必要的 } ``` @@ -58,7 +58,7 @@ for (var i = 0; i < myNodeList.length; ++i) { [for...of](/zh-CN/JavaScript/Reference/Statements/for...of) 循环**将会**正确的遍历 `NodeList` 对象: ```js -var list = document.querySelectorAll('input[type=checkbox]'); +var list = document.querySelectorAll("input[type=checkbox]"); for (var checkbox of list) { checkbox.checked = true; } @@ -69,7 +69,7 @@ for (var checkbox of list) { 也有一种使用数组 `Array` 的 {{jsxref("Array.forEach()", "Array.prototype.forEach")}} 来遍历 `NodeList` 的方法,这种方法兼容 Internet Explorer {{Deprecated_Inline}}: ```js -var list = document.querySelectorAll('input[type=checkbox]'); +var list = document.querySelectorAll("input[type=checkbox]"); Array.prototype.forEach.call(list, function (checkbox) { checkbox.checked = true; }); @@ -100,22 +100,21 @@ NodeList 的原型上除了类似数组的 `forEach` 方法之外,还有 `item 一个解决办法就是把 `Array.prototype` 上的方法添加到 `NodeList.prototype` 上。可是,要注意[扩展 DOM 对象的原型是非常危险的](http://perfectionkills.com/whats-wrong-with-extending-the-dom/),尤其是在旧版本的 Internet Explorer(6,7,8)中。 ```js -var arrayMethods = Object.getOwnPropertyNames( Array.prototype ); +var arrayMethods = Object.getOwnPropertyNames(Array.prototype); -arrayMethods.forEach( attachArrayMethodsToNodeList ); +arrayMethods.forEach(attachArrayMethodsToNodeList); -function attachArrayMethodsToNodeList(methodName) -{ - if(methodName !== "length") { +function attachArrayMethodsToNodeList(methodName) { + if (methodName !== "length") { NodeList.prototype[methodName] = Array.prototype[methodName]; } -}; +} -var divs = document.getElementsByTagName( 'div' ); -var firstDiv = divs[ 0 ]; +var divs = document.getElementsByTagName("div"); +var firstDiv = divs[0]; -firstDiv.childNodes.forEach(function( divChild ){ - divChild.parentNode.style.color = '#0F0'; +firstDiv.childNodes.forEach(function (divChild) { + divChild.parentNode.style.color = "#0F0"; }); ``` @@ -124,11 +123,11 @@ firstDiv.childNodes.forEach(function( divChild ){ ```js var forEach = Array.prototype.forEach; -var divs = document.getElementsByTagName( 'div' ); -var firstDiv = divs[ 0 ]; +var divs = document.getElementsByTagName("div"); +var firstDiv = divs[0]; -forEach.call(firstDiv.childNodes, function( divChild ){ - divChild.parentNode.style.color = '#0F0'; +forEach.call(firstDiv.childNodes, function (divChild) { + divChild.parentNode.style.color = "#0F0"; }); ``` diff --git a/files/zh-cn/web/api/nodelist/keys/index.md b/files/zh-cn/web/api/nodelist/keys/index.md index b24b5d9eb9a92e..691eff2b3cc1e3 100644 --- a/files/zh-cn/web/api/nodelist/keys/index.md +++ b/files/zh-cn/web/api/nodelist/keys/index.md @@ -32,8 +32,8 @@ node.appendChild(kid3); var list = node.childNodes; // Using for..of -for(var key of list.keys()) { - console.log(key); +for (var key of list.keys()) { + console.log(key); } ``` diff --git a/files/zh-cn/web/api/nodelist/length/index.md b/files/zh-cn/web/api/nodelist/length/index.md index 1b4a2109e6d2fd..2a34a144de1c9f 100644 --- a/files/zh-cn/web/api/nodelist/length/index.md +++ b/files/zh-cn/web/api/nodelist/length/index.md @@ -12,7 +12,7 @@ slug: Web/API/NodeList/length ## 语法 ```js -numItems =nodeList.length +numItems = nodeList.length; ``` - `numItems` 是一个整数,表示 `NodeList` 子节点的数量。 diff --git a/files/zh-cn/web/api/nodelist/values/index.md b/files/zh-cn/web/api/nodelist/values/index.md index 64733dc9618699..dff83c49432873 100644 --- a/files/zh-cn/web/api/nodelist/values/index.md +++ b/files/zh-cn/web/api/nodelist/values/index.md @@ -30,7 +30,7 @@ node.appendChild(kid3); var list = node.childNodes; // Using for..of -for(var value of list.values()) { +for (var value of list.values()) { console.log(value); } ``` diff --git a/files/zh-cn/web/api/notification/notification/index.md b/files/zh-cn/web/api/notification/notification/index.md index 5cfddd5b989ea4..8bd93b514c5b44 100644 --- a/files/zh-cn/web/api/notification/notification/index.md +++ b/files/zh-cn/web/api/notification/notification/index.md @@ -47,13 +47,12 @@ let myNotification = new Notification(title, options); In our [Emogotchi demo](http://mdn.github.io/emogotchi/) ([see source code](https://github.com/mdn/emogotchi)), we run a simple `spawnNotification()` function when we want to fire a notification — this is passed arguments to specify the body, icon and title we want, then it creates the necessary `options` object and fires the notification using the `Notification()` constructor. ```js -function spawnNotification(theBody,theIcon,theTitle) { +function spawnNotification(theBody, theIcon, theTitle) { var options = { - body: theBody, - icon: theIcon - } - var n = new Notification(theTitle,options); - + body: theBody, + icon: theIcon, + }; + var n = new Notification(theTitle, options); } ``` diff --git a/files/zh-cn/web/api/notificationevent/index.md b/files/zh-cn/web/api/notificationevent/index.md index 6ab525f019807a..db76a8bf5a027c 100644 --- a/files/zh-cn/web/api/notificationevent/index.md +++ b/files/zh-cn/web/api/notificationevent/index.md @@ -33,23 +33,25 @@ _从其父项**{{domxref("ExtendableEvent")}}**继承方法_。 ## 例 ```js -self.addEventListener('notificationclick', function(event) { - console.log('On notification click: ', event.notification.tag); +self.addEventListener("notificationclick", function (event) { + console.log("On notification click: ", event.notification.tag); event.notification.close(); // This looks to see if the current is already open and // focuses if it is - event.waitUntil(clients.matchAll({ - type: "window" - }).then(function(clientList) { - for (var i = 0; i < clientList.length; i++) { - var client = clientList[i]; - if (client.url == '/' && 'focus' in client) - return client.focus(); - } - if (clients.openWindow) - return clients.openWindow('/'); - })); + event.waitUntil( + clients + .matchAll({ + type: "window", + }) + .then(function (clientList) { + for (var i = 0; i < clientList.length; i++) { + var client = clientList[i]; + if (client.url == "/" && "focus" in client) return client.focus(); + } + if (clients.openWindow) return clients.openWindow("/"); + }), + ); }); ``` diff --git a/files/zh-cn/web/api/notifications_api/using_the_notifications_api/index.md b/files/zh-cn/web/api/notifications_api/using_the_notifications_api/index.md index e4275684052dc0..dc6e4338e7919e 100644 --- a/files/zh-cn/web/api/notifications_api/using_the_notifications_api/index.md +++ b/files/zh-cn/web/api/notifications_api/using_the_notifications_api/index.md @@ -22,9 +22,9 @@ Web Notifications API 使页面可以发出通知,通知将被显示在页面 要显示一条通知,你需要先请求适当的权限,然后你可以实例化一个 {{domxref("Notification")}} 实例: ```js -Notification.requestPermission( function(status) { +Notification.requestPermission(function (status) { console.log(status); // 仅当值为 "granted" 时显示通知 - var n = new Notification("title", {body: "notification body"}); // 显示通知 + var n = new Notification("title", { body: "notification body" }); // 显示通知 }); ``` @@ -52,7 +52,7 @@ Notification.requestPermission( function(status) { 通常你应在你的应用首次初始化的时候请求显示通知的权限: ```js -window.addEventListener('load', function () { +window.addEventListener("load", function () { Notification.requestPermission(function (status) { // 这将使我们能在 Chrome/Safari 中使用 Notification.permission if (Notification.permission !== status) { @@ -103,7 +103,7 @@ window.addEventListener('load', function () { > var n = new Notification("Hi!"); > n.onshow = function () { > setTimeout(n.close.bind(n), 5000); -> } +> }; > ``` > > 当你接收到一个“close”事件时,并不能保证这个通知是被用户关闭的。这是符合规范的,其中指出:“当一个通知被关闭时,通知的关闭动作都必须执行,不论是底层通知平台导致,还是用户导致。” @@ -119,7 +119,7 @@ window.addEventListener('load', function () { 它可能通过这样的方式处理通知: ```js -window.addEventListener('load', function () { +window.addEventListener("load", function () { // 首先,让我们检查我们是否有权限发出通知 // 如果没有,我们就请求获得权限 if (window.Notification && Notification.permission !== "granted") { @@ -130,9 +130,9 @@ window.addEventListener('load', function () { }); } - var button = document.getElementsByTagName('button')[0]; + var button = document.getElementsByTagName("button")[0]; - button.addEventListener('click', function () { + button.addEventListener("click", function () { // 如果用户同意就创建一个通知 if (window.Notification && Notification.permission === "granted") { var n = new Notification("Hi!"); @@ -189,7 +189,7 @@ window.addEventListener('load', function () { 它有可能通过这种方式处理的多个通知: ```js -window.addEventListener('load', function () { +window.addEventListener("load", function () { // 首先,我们检查是否具有权限显示通知 // 如果没有,我们就申请权限 if (window.Notification && Notification.permission !== "granted") { @@ -200,14 +200,14 @@ window.addEventListener('load', function () { }); } - var button = document.getElementsByTagName('button')[0]; + var button = document.getElementsByTagName("button")[0]; - button.addEventListener('click', function () { + button.addEventListener("click", function () { // 如果用户同意接收通知,我们就尝试发送 10 条通知 if (window.Notification && Notification.permission === "granted") { for (var i = 0; i < 10; i++) { // 感谢标记,我们应该只看到内容为 "Hi! 9" 的通知 - var n = new Notification("Hi! " + i, {tag: 'soManyNotification'}); + var n = new Notification("Hi! " + i, { tag: "soManyNotification" }); } } @@ -224,7 +224,7 @@ window.addEventListener('load', function () { if (status === "granted") { for (var i = 0; i < 10; i++) { // Thanks to the tag, we should only see the "Hi! 9" notification - var n = new Notification("Hi! " + i, {tag: 'soManyNotification'}); + var n = new Notification("Hi! " + i, { tag: "soManyNotification" }); } } diff --git a/files/zh-cn/web/api/oes_vertex_array_object/index.md b/files/zh-cn/web/api/oes_vertex_array_object/index.md index 4952ac89757750..a55bbc06040f7c 100644 --- a/files/zh-cn/web/api/oes_vertex_array_object/index.md +++ b/files/zh-cn/web/api/oes_vertex_array_object/index.md @@ -34,7 +34,7 @@ WebGL extensions are available using the {{domxref("WebGLRenderingContext.getExt ## Examples ```js -var oes_vao_ext = gl.getExtension('OES_vertex_array_object'); +var oes_vao_ext = gl.getExtension("OES_vertex_array_object"); var vao = oes_vao_ext.createVertexArrayOES(); oes_vao_ext.bindVertexArrayOES(vao); diff --git a/files/zh-cn/web/api/offlineaudiocontext/complete_event/index.md b/files/zh-cn/web/api/offlineaudiocontext/complete_event/index.md index 32267e4c9d716d..fadd36fbe61cff 100644 --- a/files/zh-cn/web/api/offlineaudiocontext/complete_event/index.md +++ b/files/zh-cn/web/api/offlineaudiocontext/complete_event/index.md @@ -1,5 +1,5 @@ --- -title: 'OfflineAudioContext: complete event' +title: "OfflineAudioContext: complete event" slug: Web/API/OfflineAudioContext/complete_event --- @@ -37,21 +37,21 @@ slug: Web/API/OfflineAudioContext/complete_event 处理完成后,您可能希望使用`oncomplete`处理程序提示用户现在可以播放音频,并启用播放按钮: ```js -offlineAudioCtx.addEventListener('complete',()=> { - console.log('Offline audio processing now complete'); - showModalDialog('Song processed and ready to play'); +offlineAudioCtx.addEventListener("complete", () => { + console.log("Offline audio processing now complete"); + showModalDialog("Song processed and ready to play"); playBtn.disabled = false; -}) +}); ``` You can also set up the event handler using the {{domxref("OfflineAudioContext.oncomplete")}} property: ```js -offlineAudioCtx.oncomplete = function() { - console.log('Offline audio processing now complete'); - showModalDialog('Song processed and ready to play'); +offlineAudioCtx.oncomplete = function () { + console.log("Offline audio processing now complete"); + showModalDialog("Song processed and ready to play"); playBtn.disabled = false; -} +}; ``` ## Specifications diff --git a/files/zh-cn/web/api/offlineaudiocontext/index.md b/files/zh-cn/web/api/offlineaudiocontext/index.md index f22c9affb4e0e0..29b6b52bba2063 100644 --- a/files/zh-cn/web/api/offlineaudiocontext/index.md +++ b/files/zh-cn/web/api/offlineaudiocontext/index.md @@ -49,7 +49,7 @@ _从父级 {{domxref("AudioContext")}} 和 {{domxref("EventTarget")}} 获取方 // 定义一个在线或者离线的音频上下文 var audioCtx = new AudioContext(); -var offlineCtx = new OfflineAudioContext(2,44100*40,44100); +var offlineCtx = new OfflineAudioContext(2, 44100 * 40, 44100); source = offlineCtx.createBufferSource(); @@ -60,36 +60,40 @@ source = offlineCtx.createBufferSource(); function getData() { request = new XMLHttpRequest(); - request.open('GET', 'viper.ogg', true); + request.open("GET", "viper.ogg", true); - request.responseType = 'arraybuffer'; + request.responseType = "arraybuffer"; - request.onload = function() { + request.onload = function () { var audioData = request.response; - audioCtx.decodeAudioData(audioData, function(buffer) { + audioCtx.decodeAudioData(audioData, function (buffer) { myBuffer = buffer; source.buffer = myBuffer; source.connect(offlineCtx.destination); source.start(); //source.loop = true; - offlineCtx.startRendering().then(function(renderedBuffer) { - console.log('渲染完全成功'); - var audioCtx = new (window.AudioContext || window.webkitAudioContext)(); - var song = audioCtx.createBufferSource(); - song.buffer = renderedBuffer; - - song.connect(audioCtx.destination); - - play.onclick = function() { - song.start(); - } - }).catch(function(err) { - console.log('渲染失败:' + err); + offlineCtx + .startRendering() + .then(function (renderedBuffer) { + console.log("渲染完全成功"); + var audioCtx = new (window.AudioContext || + window.webkitAudioContext)(); + var song = audioCtx.createBufferSource(); + song.buffer = renderedBuffer; + + song.connect(audioCtx.destination); + + play.onclick = function () { + song.start(); + }; + }) + .catch(function (err) { + console.log("渲染失败:" + err); // 注意:当 OfflineAudioContext 上 startRendering 被立刻调用,Promise 应该被 reject - }); + }); }); - } + }; request.send(); } diff --git a/files/zh-cn/web/api/offlineaudiocontext/offlineaudiocontext/index.md b/files/zh-cn/web/api/offlineaudiocontext/offlineaudiocontext/index.md index f9b23ae51b4ddd..de224cb8760a86 100644 --- a/files/zh-cn/web/api/offlineaudiocontext/offlineaudiocontext/index.md +++ b/files/zh-cn/web/api/offlineaudiocontext/offlineaudiocontext/index.md @@ -10,7 +10,7 @@ slug: Web/API/OfflineAudioContext/OfflineAudioContext ## 语法 ```js -var myOfflineAudio = new OfflineAudioContext(numOfChannels,length,sampleRate); +var myOfflineAudio = new OfflineAudioContext(numOfChannels, length, sampleRate); ``` ### 参数 @@ -32,7 +32,7 @@ var myOfflineAudio = new OfflineAudioContext(numOfChannels,length,sampleRate); // 定义一个在线或者离线的音频上下文 var audioCtx = new AudioContext(); -var offlineCtx = new OfflineAudioContext(2,44100*40,44100); +var offlineCtx = new OfflineAudioContext(2, 44100 * 40, 44100); source = offlineCtx.createBufferSource(); diff --git a/files/zh-cn/web/api/offscreencanvas/index.md b/files/zh-cn/web/api/offscreencanvas/index.md index 7da4e3f608ea9a..e70716b0b56a7b 100644 --- a/files/zh-cn/web/api/offscreencanvas/index.md +++ b/files/zh-cn/web/api/offscreencanvas/index.md @@ -39,8 +39,7 @@ slug: Web/API/OffscreenCanvas 提供两个 {{HTMLElement("canvas")}} 元素 ```html - - + ``` 下面的代码会用 `OffscreenCanvas` 提供渲染结果,就像上面描述的一样。 @@ -50,7 +49,7 @@ var one = document.getElementById("one").getContext("bitmaprenderer"); var two = document.getElementById("two").getContext("bitmaprenderer"); var offscreen = new OffscreenCanvas(256, 256); -var gl = offscreen.getContext('webgl'); +var gl = offscreen.getContext("webgl"); // ... some drawing for the first canvas using the gl context ... @@ -76,13 +75,13 @@ var htmlCanvas = document.getElementById("canvas"); var offscreen = htmlCanvas.transferControlToOffscreen(); var worker = new Worker("offscreencanvas.js"); -worker.postMessage({canvas: offscreen}, [offscreen]); +worker.postMessage({ canvas: offscreen }, [offscreen]); ``` offscreencanvas.js (web work 代码): ```js -onmessage = function(evt) { +onmessage = function (evt) { var canvas = evt.data.canvas; var gl = canvas.getContext("webgl"); @@ -96,7 +95,7 @@ onmessage = function(evt) { 也可以在 worker 中使用 requestAnimationFrame ```js -onmessage = function(evt) { +onmessage = function (evt) { const canvas = evt.data.canvas; const gl = canvas.getContext("webgl"); diff --git a/files/zh-cn/web/api/origin/index.md b/files/zh-cn/web/api/origin/index.md index 47c8c28321ca02..706c3027fe431e 100644 --- a/files/zh-cn/web/api/origin/index.md +++ b/files/zh-cn/web/api/origin/index.md @@ -22,7 +22,7 @@ A {{domxref("USVString")}}. Executed from inside a worker script, the following snippet will log the worker's global scope's origin to the console each time it receives a message ```js -onmessage = function() { +onmessage = function () { console.log(self.origin); }; ``` diff --git a/files/zh-cn/web/api/oscillatornode/detune/index.md b/files/zh-cn/web/api/oscillatornode/detune/index.md index 1166aa6a7af804..b5f873988033b2 100644 --- a/files/zh-cn/web/api/oscillatornode/detune/index.md +++ b/files/zh-cn/web/api/oscillatornode/detune/index.md @@ -31,7 +31,7 @@ var audioCtx = new (window.AudioContext || window.webkitAudioContext)(); // create Oscillator node var oscillator = audioCtx.createOscillator(); -oscillator.type = 'square'; +oscillator.type = "square"; oscillator.frequency.value = 440; // value in hertz oscillator.detune.value = 100; // value in cents oscillator.start(); diff --git a/files/zh-cn/web/api/oscillatornode/frequency/index.md b/files/zh-cn/web/api/oscillatornode/frequency/index.md index 74f7c671718ea5..ff024c53c59287 100644 --- a/files/zh-cn/web/api/oscillatornode/frequency/index.md +++ b/files/zh-cn/web/api/oscillatornode/frequency/index.md @@ -31,7 +31,7 @@ var audioCtx = new (window.AudioContext || window.webkitAudioContext)(); // create Oscillator node var oscillator = audioCtx.createOscillator(); -oscillator.type = 'square'; +oscillator.type = "square"; oscillator.frequency.value = 440; // value in hertz oscillator.start(); ``` diff --git a/files/zh-cn/web/api/oscillatornode/index.md b/files/zh-cn/web/api/oscillatornode/index.md index 2203bfd1ecf531..5e9c2d4eaccb3a 100644 --- a/files/zh-cn/web/api/oscillatornode/index.md +++ b/files/zh-cn/web/api/oscillatornode/index.md @@ -68,7 +68,7 @@ var audioCtx = new (window.AudioContext || window.webkitAudioContext)(); // create Oscillator node var oscillator = audioCtx.createOscillator(); -oscillator.type = 'square'; +oscillator.type = "square"; oscillator.frequency.value = 440; // value in hertz oscillator.connect(audioCtx.destination); oscillator.start(); diff --git a/files/zh-cn/web/api/page_visibility_api/index.md b/files/zh-cn/web/api/page_visibility_api/index.md index 7a2357405c2366..e5bf3e10ac551a 100644 --- a/files/zh-cn/web/api/page_visibility_api/index.md +++ b/files/zh-cn/web/api/page_visibility_api/index.md @@ -55,7 +55,8 @@ Some processes are exempt from this throttling behavior. In these cases, you can ```js // 设置隐藏属性和改变可见属性的事件的名称 var hidden, visibilityChange; -if (typeof document.hidden !== "undefined") { // Opera 12.10 and Firefox 18 and later support +if (typeof document.hidden !== "undefined") { + // Opera 12.10 and Firefox 18 and later support hidden = "hidden"; visibilityChange = "visibilitychange"; } else if (typeof document.msHidden !== "undefined") { @@ -79,23 +80,35 @@ function handleVisibilityChange() { } // 如果浏览器不支持 addEventListener 或 Page Visibility API 给出警告 -if (typeof document.addEventListener === "undefined" || typeof document[hidden] === "undefined") { - console.log("This demo requires a browser, such as Google Chrome or Firefox, that supports the Page Visibility API."); +if ( + typeof document.addEventListener === "undefined" || + typeof document[hidden] === "undefined" +) { + console.log( + "This demo requires a browser, such as Google Chrome or Firefox, that supports the Page Visibility API.", + ); } else { // 处理页面可见属性的改变 document.addEventListener(visibilityChange, handleVisibilityChange, false); // 当视频暂停,设置 title // This shows the paused - videoElement.addEventListener("pause", function(){ - document.title = 'Paused'; - }, false); + videoElement.addEventListener( + "pause", + function () { + document.title = "Paused"; + }, + false, + ); // 当视频播放,设置 title - videoElement.addEventListener("play", function(){ - document.title = 'Playing'; - }, false); - + videoElement.addEventListener( + "play", + function () { + document.title = "Playing"; + }, + false, + ); } ``` @@ -121,7 +134,7 @@ if (typeof document.addEventListener === "undefined" || typeof document[hidden] function handleVisibilityChange() { if (document.hidden) { pauseSimulation(); - } else { + } else { startSimulation(); } } diff --git a/files/zh-cn/web/api/pagetransitionevent/index.md b/files/zh-cn/web/api/pagetransitionevent/index.md index e3ad2128094610..1d086a30bfd30a 100644 --- a/files/zh-cn/web/api/pagetransitionevent/index.md +++ b/files/zh-cn/web/api/pagetransitionevent/index.md @@ -20,10 +20,9 @@ EventPageTransitionEvent ### HTML ```html - + - - + ``` @@ -31,11 +30,11 @@ EventPageTransitionEvent ```js function myFunction(event) { - if (event.persisted) { - alert("The page was cached by the browser"); - } else { - alert("The page was NOT cached by the browser"); - } + if (event.persisted) { + alert("The page was cached by the browser"); + } else { + alert("The page was NOT cached by the browser"); + } } ``` diff --git a/files/zh-cn/web/api/pagetransitionevent/persisted/index.md b/files/zh-cn/web/api/pagetransitionevent/persisted/index.md index eacf789ab00436..fc32c031c55e85 100644 --- a/files/zh-cn/web/api/pagetransitionevent/persisted/index.md +++ b/files/zh-cn/web/api/pagetransitionevent/persisted/index.md @@ -10,9 +10,9 @@ slug: Web/API/PageTransitionEvent/persisted ## Syntax ```js -window.addEventListener('pageshow', function(event) { +window.addEventListener("pageshow", function (event) { if (event.persisted) { - console.log('Page was loaded from cache.'); + console.log("Page was loaded from cache."); } }); ``` diff --git a/files/zh-cn/web/api/path2d/addpath/index.md b/files/zh-cn/web/api/path2d/addpath/index.md index d39ca88f49d779..e970d224db610c 100644 --- a/files/zh-cn/web/api/path2d/addpath/index.md +++ b/files/zh-cn/web/api/path2d/addpath/index.md @@ -35,8 +35,8 @@ void path.addPath(path [, transform]); #### JavaScript ```js -const canvas = document.getElementById('canvas'); -const ctx = canvas.getContext('2d'); +const canvas = document.getElementById("canvas"); +const ctx = canvas.getContext("2d"); // Create first path and add a rectangle let p1 = new Path2D(); @@ -48,9 +48,12 @@ p2.rect(0, 0, 100, 75); // Create transformation matrix that moves 200 points to the right let m = new DOMMatrix(); -m.a = 1; m.b = 0; -m.c = 0; m.d = 1; -m.e = 200; m.f = 0; +m.a = 1; +m.b = 0; +m.c = 0; +m.d = 1; +m.e = 200; +m.f = 0; // Add second path to the first path p1.addPath(p2, m); diff --git a/files/zh-cn/web/api/path2d/path2d/index.md b/files/zh-cn/web/api/path2d/path2d/index.md index 6a81dc52c62087..c1e35de1f603d8 100644 --- a/files/zh-cn/web/api/path2d/path2d/index.md +++ b/files/zh-cn/web/api/path2d/path2d/index.md @@ -33,8 +33,8 @@ new Path2D(d); ``` ```js -const canvas = document.getElementById('canvas'); -const ctx = canvas.getContext('2d'); +const canvas = document.getElementById("canvas"); +const ctx = canvas.getContext("2d"); let path1 = new Path2D(); path1.rect(10, 10, 100, 100); @@ -57,10 +57,10 @@ ctx.stroke(path2); ``` ```js -const canvas = document.getElementById('canvas'); -const ctx = canvas.getContext('2d'); +const canvas = document.getElementById("canvas"); +const ctx = canvas.getContext("2d"); -let p = new Path2D('M10 10 h 80 v 80 h -80 Z'); +let p = new Path2D("M10 10 h 80 v 80 h -80 Z"); ctx.fill(p); ``` diff --git a/files/zh-cn/web/api/payment_request_api/concepts/index.md b/files/zh-cn/web/api/payment_request_api/concepts/index.md index b049b05b6abed6..1e61b6dd946f2d 100644 --- a/files/zh-cn/web/api/payment_request_api/concepts/index.md +++ b/files/zh-cn/web/api/payment_request_api/concepts/index.md @@ -59,9 +59,9 @@ slug: Web/API/Payment_Request_API/Concepts 具体的认证方式由交易处理机决定,也完全可以省去这种认证。最终,网站或应用唯一要做的就是就是获取商家的认证密钥并传输给 {{domxref("MerchantValidationEvent.complete", "complete()")}} 事件的方法。 ```js -paymentRequest.onmerchantvalidation = function(event) { +paymentRequest.onmerchantvalidation = function (event) { event.complete(fetchValidationData(event.validationURL)); -} +}; ``` 在这个例子中,由`fetchValidationData()`方法加载由`validationURL`提供的认证信息。要注意到的是,这个方法必须由商家服务器转发,因为通常情况下,客户端不会主动访问用于认证的 URL。 diff --git a/files/zh-cn/web/api/performance/clearresourcetimings/index.md b/files/zh-cn/web/api/performance/clearresourcetimings/index.md index 1be6def72a4054..5bd8cb26a711cf 100644 --- a/files/zh-cn/web/api/performance/clearresourcetimings/index.md +++ b/files/zh-cn/web/api/performance/clearresourcetimings/index.md @@ -49,10 +49,8 @@ function clear_performance_timings() { } // getEntries should now return zero var p = performance.getEntriesByType("resource"); - if (p.length == 0) - console.log("... Performance data buffer cleared"); - else - console.log("... Performance data buffer NOT cleared!"); + if (p.length == 0) console.log("... Performance data buffer cleared"); + else console.log("... Performance data buffer NOT cleared!"); } ``` diff --git a/files/zh-cn/web/api/performance/getentries/index.md b/files/zh-cn/web/api/performance/getentries/index.md index 4947d6269b781a..f6140c35405fbd 100644 --- a/files/zh-cn/web/api/performance/getentries/index.md +++ b/files/zh-cn/web/api/performance/getentries/index.md @@ -62,48 +62,68 @@ function use_PerformanceEntry_methods() { // Use getEntries() to iterate through the each entry var p = performance.getEntries(); - for (var i=0; i < p.length; i++) { + for (var i = 0; i < p.length; i++) { log("Entry[" + i + "]"); check_PerformanceEntry(p[i]); } // Use getEntries(name, entryType) to get specific entries - p = performance.getEntries({name : "Begin", entryType: "mark"}); - for (var i=0; i < p.length; i++) { + p = performance.getEntries({ name: "Begin", entryType: "mark" }); + for (var i = 0; i < p.length; i++) { log("Begin[" + i + "]"); check_PerformanceEntry(p[i]); } // Use getEntriesByType() to get all "mark" entries p = performance.getEntriesByType("mark"); - for (var i=0; i < p.length; i++) { - log ("Mark only entry[" + i + "]: name = " + p[i].name + - "; startTime = " + p[i].startTime + - "; duration = " + p[i].duration); + for (var i = 0; i < p.length; i++) { + log( + "Mark only entry[" + + i + + "]: name = " + + p[i].name + + "; startTime = " + + p[i].startTime + + "; duration = " + + p[i].duration, + ); } // Use getEntriesByName() to get all "mark" entries named "Begin" p = performance.getEntriesByName("Begin", "mark"); - for (var i=0; i < p.length; i++) { - log ("Mark and Begin entry[" + i + "]: name = " + p[i].name + - "; startTime = " + p[i].startTime + - "; duration = " + p[i].duration); + for (var i = 0; i < p.length; i++) { + log( + "Mark and Begin entry[" + + i + + "]: name = " + + p[i].name + + "; startTime = " + + p[i].startTime + + "; duration = " + + p[i].duration, + ); } } //entryType,name,initiatorType Examples var p = performance.getEntries(); -var ptyps = p.map((ele) => {return(ele.entryType)}); +var ptyps = p.map((ele) => { + return ele.entryType; +}); //Array(94) [ "navigation", "resource", "resource", "resource", "resource", "resource", "resource", "resource", "resource", "resource", … ] -var pnms = p.map((ele) => {return(ele.name)}); +var pnms = p.map((ele) => { + return ele.name; +}); //Array(94) [ "document", "https://csdnimg.cn/public/static/css/avatar.css", "https://csdnimg.cn/public/common/libs/jquery/jquery-1.9.1.min.js", "https://csdnimg.cn/rabbit/exposure-click/main-1.0.5.js", "https://csdnimg.cn/release/phoenix/production/main-e96db8abdf.js", "https://csdnimg.cn/pubfooter/js/tracking-1.0.2.js", "https://csdnimg.cn/public/common/toolbar/js/content_toolbar.js", "https://csdnimg.cn/release/phoenix/production/markdown_views-ea0013b516.css", "https://csdnimg.cn/search/baidu_search-1.1.2.js?v=201802071056&autorun=true&install=true&keyword=%E5%B0%8F%E7%A8%8B%E5%BA%8F%E6%89%A7%E8%A1%8C%E9%A1%BA%E5%BA%8F", "https://csdnimg.cn/release/phoenix/production/main-f869aa95a4.css", … ] -var pityps = p.map((ele) => {return(ele.initiatorType)}); +var pityps = p.map((ele) => { + return ele.initiatorType; +}); //Array(94) [ "navigation", "link", "script", "script", "script", "script", "script", "link", "script", "link", … ] -Specifications +Specifications; ``` {{Specifications}} diff --git a/files/zh-cn/web/api/performance/getentriesbyname/index.md b/files/zh-cn/web/api/performance/getentriesbyname/index.md index 01acf6b780b965..6abb38f2b1a3f3 100644 --- a/files/zh-cn/web/api/performance/getentriesbyname/index.md +++ b/files/zh-cn/web/api/performance/getentriesbyname/index.md @@ -48,32 +48,46 @@ function use_PerformanceEntry_methods() { // Use getEntries() to iterate through the each entry var p = performance.getEntries(); - for (var i=0; i < p.length; i++) { + for (var i = 0; i < p.length; i++) { log("Entry[" + i + "]"); check_PerformanceEntry(p[i]); } // Use getEntries(name, entryType) to get specific entries - p = performance.getEntries({name : "Begin", entryType: "mark"}); - for (var i=0; i < p.length; i++) { + p = performance.getEntries({ name: "Begin", entryType: "mark" }); + for (var i = 0; i < p.length; i++) { log("Begin[" + i + "]"); check_PerformanceEntry(p[i]); } // Use getEntriesByType() to get all "mark" entries p = performance.getEntriesByType("mark"); - for (var i=0; i < p.length; i++) { - log ("Mark only entry[" + i + "]: name = " + p[i].name + - "; startTime = " + p[i].startTime + - "; duration = " + p[i].duration); + for (var i = 0; i < p.length; i++) { + log( + "Mark only entry[" + + i + + "]: name = " + + p[i].name + + "; startTime = " + + p[i].startTime + + "; duration = " + + p[i].duration, + ); } // Use getEntriesByName() to get all "mark" entries named "Begin" p = performance.getEntriesByName("Begin", "mark"); - for (var i=0; i < p.length; i++) { - log ("Mark and Begin entry[" + i + "]: name = " + p[i].name + - "; startTime = " + p[i].startTime + - "; duration = " + p[i].duration); + for (var i = 0; i < p.length; i++) { + log( + "Mark and Begin entry[" + + i + + "]: name = " + + p[i].name + + "; startTime = " + + p[i].startTime + + "; duration = " + + p[i].duration, + ); } } ``` diff --git a/files/zh-cn/web/api/performance/getentriesbytype/index.md b/files/zh-cn/web/api/performance/getentriesbytype/index.md index 523777caad3d74..a369c19db5e296 100644 --- a/files/zh-cn/web/api/performance/getentriesbytype/index.md +++ b/files/zh-cn/web/api/performance/getentriesbytype/index.md @@ -48,32 +48,46 @@ function usePerformanceEntryMethods() { // Use getEntries() to iterate through the each entry var p = performance.getEntries(); - for (var i=0; i < p.length; i++) { + for (var i = 0; i < p.length; i++) { log("Entry[" + i + "]"); checkPerformanceEntry(p[i]); } // Use getEntries(name, entryType) to get specific entries - p = performance.getEntries({name : "Begin", entryType: "mark"}); - for (var i=0; i < p.length; i++) { + p = performance.getEntries({ name: "Begin", entryType: "mark" }); + for (var i = 0; i < p.length; i++) { log("Begin[" + i + "]"); checkPerformanceEntry(p[i]); } // Use getEntriesByType() to get all "mark" entries p = performance.getEntriesByType("mark"); - for (var i=0; i < p.length; i++) { - log ("Mark only entry[" + i + "]: name = " + p[i].name + - "; startTime = " + p[i].startTime + - "; duration = " + p[i].duration); + for (var i = 0; i < p.length; i++) { + log( + "Mark only entry[" + + i + + "]: name = " + + p[i].name + + "; startTime = " + + p[i].startTime + + "; duration = " + + p[i].duration, + ); } // Use getEntriesByName() to get all "mark" entries named "Begin" p = performance.getEntriesByName("Begin", "mark"); - for (var i=0; i < p.length; i++) { - log ("Mark and Begin entry[" + i + "]: name = " + p[i].name + - "; startTime = " + p[i].startTime + - "; duration = " + p[i].duration); + for (var i = 0; i < p.length; i++) { + log( + "Mark and Begin entry[" + + i + + "]: name = " + + p[i].name + + "; startTime = " + + p[i].startTime + + "; duration = " + + p[i].duration, + ); } } ``` diff --git a/files/zh-cn/web/api/performance/measure/index.md b/files/zh-cn/web/api/performance/measure/index.md index fea829e04f7d68..381f93afcc3e0f 100644 --- a/files/zh-cn/web/api/performance/measure/index.md +++ b/files/zh-cn/web/api/performance/measure/index.md @@ -46,22 +46,18 @@ performance.measure(name, startMark, endMark); performance.mark("mySetTimeout-start"); // 等待一些时间。 -setTimeout(function() { +setTimeout(function () { // 标志时间的结束。 performance.mark("mySetTimeout-end"); // 测量两个不同的标志。 - performance.measure( - "mySetTimeout", - "mySetTimeout-start", - "mySetTimeout-end" - ); + performance.measure("mySetTimeout", "mySetTimeout-start", "mySetTimeout-end"); // 获取所有的测量输出。 // 在这个例子中只有一个。 var measures = performance.getEntriesByName("mySetTimeout"); var measure = measures[0]; - console.log("setTimeout milliseconds:", measure.duration) + console.log("setTimeout milliseconds:", measure.duration); // 清除存储的标志位 performance.clearMarks(); diff --git a/files/zh-cn/web/api/performance/now/index.md b/files/zh-cn/web/api/performance/now/index.md index 696b97277646d5..5dddd8d4b351dd 100644 --- a/files/zh-cn/web/api/performance/now/index.md +++ b/files/zh-cn/web/api/performance/now/index.md @@ -30,7 +30,7 @@ const t = window.performance.now(); const t0 = window.performance.now(); doSomething(); const t1 = window.performance.now(); -console.log("doSomething 函数执行了" + (t1 - t0) + "毫秒。") +console.log("doSomething 函数执行了" + (t1 - t0) + "毫秒。"); ``` 和 JavaScript 中其他可用的时间类函数(比如[`Date.now`](/zh-CN/docs/JavaScript/Reference/Global_Objects/Date/now))不同的是,`window.performance.now()`返回的时间戳没有被限制在一毫秒的精确度内,相反,它们以浮点数的形式表示时间,精度最高可达微秒级。 diff --git a/files/zh-cn/web/api/performanceentry/duration/index.md b/files/zh-cn/web/api/performanceentry/duration/index.md index 0ff9338f2832a7..e7f9c08774bc0a 100644 --- a/files/zh-cn/web/api/performanceentry/duration/index.md +++ b/files/zh-cn/web/api/performanceentry/duration/index.md @@ -49,7 +49,7 @@ function run_PerformanceEntry() { // Use getEntries() to iterate through the each entry var p = performance.getEntries(); - for (var i=0; i < p.length; i++) { + for (var i = 0; i < p.length; i++) { log("Entry[" + i + "]"); check_PerformanceEntry(p[i]); } @@ -58,15 +58,13 @@ function check_PerformanceEntry(obj) { var properties = ["name", "entryType", "startTime", "duration"]; var methods = ["toJSON"]; - for (var i=0; i < properties.length; i++) { + for (var i = 0; i < 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"); + if (supported) log("..." + properties[i] + " = " + obj[properties[i]]); + else log("..." + properties[i] + " = Not supported"); } - for (var i=0; i < methods.length; i++) { + for (var i = 0; i < methods.length; i++) { // check each method var supported = typeof obj[methods[i]] == "function"; if (supported) { diff --git a/files/zh-cn/web/api/performanceentry/entrytype/index.md b/files/zh-cn/web/api/performanceentry/entrytype/index.md index c66326df8743c0..8f8b2ee5f73810 100644 --- a/files/zh-cn/web/api/performanceentry/entrytype/index.md +++ b/files/zh-cn/web/api/performanceentry/entrytype/index.md @@ -17,13 +17,13 @@ var type = entry.entryType; 返回值取决于 `PerformanceEntry` 对象的 subtype,entryType 的取值会影响{{domxref('PerformanceEntry.name')}} 属性,具体如下表所示。 -| Value | Subtype | Type of name property | Description of name property | -| --------------------- | ---------------------------------------------------------------------------------------------------------- | -------------------------------- | ------------------------------------------------------------------------------------------------------------------------------- | -| `frame`, `navigation` | {{domxref('PerformanceFrameTiming')}}, {{domxref('PerformanceNavigationTiming')}} | {{domxref("URL")}} | The document's address. | -| `resource` | {{domxref('PerformanceResourceTiming')}} | {{domxref("URL")}} | The resolved URL of the requested resource. This value doesn't change even if the request is redirected. | -| `mark` | {{domxref('PerformanceMark')}} | {{domxref("DOMString")}} | The name used when the mark was created by calling {{domxref("Performance.mark","performance.mark()")}}. | -| `measure` | {{domxref('PerformanceMeasure')}} | {{domxref("DOMString")}} | name used when the measure was created by calling {{domxref("Performance.measure","performance.measure()")}}. | -| `paint` | {{domxref('PerformancePaintTiming')}} | {{domxref("DOMString")}} | Either `'first-paint'` or `'first-contentful-paint'`. | +| Value | Subtype | Type of name property | Description of name property | +| --------------------- | --------------------------------------------------------------------------------- | ------------------------ | ------------------------------------------------------------------------------------------------------------- | +| `frame`, `navigation` | {{domxref('PerformanceFrameTiming')}}, {{domxref('PerformanceNavigationTiming')}} | {{domxref("URL")}} | The document's address. | +| `resource` | {{domxref('PerformanceResourceTiming')}} | {{domxref("URL")}} | The resolved URL of the requested resource. This value doesn't change even if the request is redirected. | +| `mark` | {{domxref('PerformanceMark')}} | {{domxref("DOMString")}} | The name used when the mark was created by calling {{domxref("Performance.mark","performance.mark()")}}. | +| `measure` | {{domxref('PerformanceMeasure')}} | {{domxref("DOMString")}} | name used when the measure was created by calling {{domxref("Performance.measure","performance.measure()")}}. | +| `paint` | {{domxref('PerformancePaintTiming')}} | {{domxref("DOMString")}} | Either `'first-paint'` or `'first-contentful-paint'`. | ## 范例 @@ -31,7 +31,6 @@ var type = entry.entryType; ```js function run_PerformanceEntry() { - // check for feature support before continuing if (performance.mark === undefined) { console.log("performance.mark not supported"); @@ -52,11 +51,10 @@ function run_PerformanceEntry() { //entriesNamedBegin[0].name // "begin" - for (var i=0; i < entriesNamedBegin.length; i++) { - var typeOfEntry = entriesNamedBegin[i].entryType; - console.log("Entry is type: " + typeOfEntry); + for (var i = 0; i < entriesNamedBegin.length; i++) { + var typeOfEntry = entriesNamedBegin[i].entryType; + console.log("Entry is type: " + typeOfEntry); } - } ``` diff --git a/files/zh-cn/web/api/performanceentry/index.md b/files/zh-cn/web/api/performanceentry/index.md index 7fff170d6c0cfa..41609b79f67207 100644 --- a/files/zh-cn/web/api/performanceentry/index.md +++ b/files/zh-cn/web/api/performanceentry/index.md @@ -33,18 +33,15 @@ Note: Performance 对象暴露给了 {{domxref("Window")}} 和 {{domxref("Worker function print_PerformanceEntries() { // Use getEntries() to get a list of all performance entries var p = performance.getEntries(); - for (var i=0; i < p.length; i++) { + for (var i = 0; i < p.length; i++) { console.log("PerformanceEntry[" + i + "]"); print_PerformanceEntry(p[i]); } } function print_PerformanceEntry(perfEntry) { - var properties = ["name", - "entryType", - "startTime", - "duration"]; + var properties = ["name", "entryType", "startTime", "duration"]; - for (var i=0; i < properties.length; i++) { + for (var i = 0; i < properties.length; i++) { // check each property var supported = properties[i] in perfEntry; if (supported) { diff --git a/files/zh-cn/web/api/performanceentry/name/index.md b/files/zh-cn/web/api/performanceentry/name/index.md index 1cacdb0ed657c6..6c3073ae9a4b28 100644 --- a/files/zh-cn/web/api/performanceentry/name/index.md +++ b/files/zh-cn/web/api/performanceentry/name/index.md @@ -17,13 +17,13 @@ var name = entry.name; 返回值取决于`PerformanceEntry` 对象的 subtype 和{{domxref("PerformanceEntry.entryType")}}的值,如下表所示。 -| Value | Subtype | entryType values | Description | -| -------------------------------- | ---------------------------------------------------------------------------------------------------------- | --------------------- | ------------------------------------------------------------------------------------------------------------------------------- | -| {{domxref("URL")}} | {{domxref('PerformanceFrameTiming')}}, {{domxref('PerformanceNavigationTiming')}} | `frame`, `navigation` | The document's address. | -| {{domxref("URL")}} | {{domxref('PerformanceResourceTiming')}} | `resource` | The resolved URL of the requested resource. This value doesn't change even if the request is redirected. | -| {{domxref("DOMString")}} | {{domxref('PerformanceMark')}} | `mark` | The name used when the mark was created by calling {{domxref("Performance.mark","performance.mark()")}}. | -| {{domxref("DOMString")}} | {{domxref('PerformanceMeasure')}} | `measure` | name used when the measure was created by calling {{domxref("Performance.measure","performance.measure()")}}. | -| {{domxref("DOMString")}} | {{domxref('PerformancePaintTiming')}} | `paint` | Either `'first-paint'` or `'first-contentful-paint'`. | +| Value | Subtype | entryType values | Description | +| ------------------------ | --------------------------------------------------------------------------------- | --------------------- | ------------------------------------------------------------------------------------------------------------- | +| {{domxref("URL")}} | {{domxref('PerformanceFrameTiming')}}, {{domxref('PerformanceNavigationTiming')}} | `frame`, `navigation` | The document's address. | +| {{domxref("URL")}} | {{domxref('PerformanceResourceTiming')}} | `resource` | The resolved URL of the requested resource. This value doesn't change even if the request is redirected. | +| {{domxref("DOMString")}} | {{domxref('PerformanceMark')}} | `mark` | The name used when the mark was created by calling {{domxref("Performance.mark","performance.mark()")}}. | +| {{domxref("DOMString")}} | {{domxref('PerformanceMeasure')}} | `measure` | name used when the measure was created by calling {{domxref("Performance.measure","performance.measure()")}}. | +| {{domxref("DOMString")}} | {{domxref('PerformancePaintTiming')}} | `paint` | Either `'first-paint'` or `'first-contentful-paint'`. | ## 用例 @@ -45,61 +45,59 @@ function run_PerformanceEntry() { // Use getEntries() to iterate through the each entry var p = performance.getEntries(); - for (var i=0; i < p.length; i++) { + for (var i = 0; i < 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] - // +// +//例如上面 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 < properties.length; i++) { + for (var i = 0; i < 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"); + if (supported) log("..." + properties[i] + " = " + obj[properties[i]]); + else log("..." + properties[i] + " = Not supported"); } - for (var i=0; i < methods.length; i++) { + for (var i = 0; i < methods.length; i++) { // check each method var supported = typeof obj[methods[i]] == "function"; if (supported) { diff --git a/files/zh-cn/web/api/performanceentry/tojson/index.md b/files/zh-cn/web/api/performanceentry/tojson/index.md index cdbaa41431770b..5064a0d6333573 100644 --- a/files/zh-cn/web/api/performanceentry/tojson/index.md +++ b/files/zh-cn/web/api/performanceentry/tojson/index.md @@ -42,7 +42,7 @@ function run_PerformanceEntry() { // Use getEntries() to iterate through the each entry var p = performance.getEntries(); - for (var i=0; i < p.length; i++) { + for (var i = 0; i < p.length; i++) { log("Entry[" + i + "]"); check_PerformanceEntry(p[i]); } @@ -51,15 +51,13 @@ function check_PerformanceEntry(obj) { var properties = ["name", "entryType", "startTime", "duration"]; var methods = ["toJSON"]; - for (var i=0; i < properties.length; i++) { + for (var i = 0; i < 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"); + if (supported) log("..." + properties[i] + " = " + obj[properties[i]]); + else log("..." + properties[i] + " = Not supported"); } - for (var i=0; i < methods.length; i++) { + for (var i = 0; i < methods.length; i++) { // check each method var supported = typeof obj[methods[i]] == "function"; if (supported) { diff --git a/files/zh-cn/web/api/performancelongtasktiming/index.md b/files/zh-cn/web/api/performancelongtasktiming/index.md index 1f7aa155d066b7..01d2e0c5d1bbee 100644 --- a/files/zh-cn/web/api/performancelongtasktiming/index.md +++ b/files/zh-cn/web/api/performancelongtasktiming/index.md @@ -40,16 +40,16 @@ original_slug: Web/API/Long_Tasks_API ## 用法 ```js -var observer = new PerformanceObserver(function(list) { - var perfEntries = list.getEntries(); - for (var i = 0; i < perfEntries.length; i++) { - // Process long task notifications: - // report back for analytics and monitoring - // ... - } +var observer = new PerformanceObserver(function (list) { + var perfEntries = list.getEntries(); + for (var i = 0; i < perfEntries.length; i++) { + // Process long task notifications: + // report back for analytics and monitoring + // ... + } }); // register observer for long task notifications -observer.observe({entryTypes: ["longtask"]}); +observer.observe({ entryTypes: ["longtask"] }); // Long script execution after this will result in queueing // and receiving "longtask" entries in the observer. ``` diff --git a/files/zh-cn/web/api/performanceobserver/disconnect/index.md b/files/zh-cn/web/api/performanceobserver/disconnect/index.md index e051ccca3fcd44..dd0484381b48d8 100644 --- a/files/zh-cn/web/api/performanceobserver/disconnect/index.md +++ b/files/zh-cn/web/api/performanceobserver/disconnect/index.md @@ -10,7 +10,7 @@ slug: Web/API/PerformanceObserver/disconnect ## 语法 ```js -disconnect() +disconnect(); ``` ### 参数 @@ -24,13 +24,13 @@ disconnect() ## 示例 ```js -var observer = new PerformanceObserver(function(list, obj) { +var observer = new PerformanceObserver(function (list, obj) { var entries = list.getEntries(); - for (var i=0; i < entries.length; i++) { + for (var i = 0; i < entries.length; i++) { // Process "mark" and "frame" events } }); -observer.observe({entryTypes: ["mark", "frame"]}); +observer.observe({ entryTypes: ["mark", "frame"] }); function perf_observer(list, observer) { // Process the "measure" event @@ -39,7 +39,7 @@ function perf_observer(list, observer) { observer.disconnect(); } var observer2 = new PerformanceObserver(perf_observer); -observer2.observe({entryTypes: ["measure"]}); +observer2.observe({ entryTypes: ["measure"] }); ``` ## 规范 diff --git a/files/zh-cn/web/api/performanceobserver/index.md b/files/zh-cn/web/api/performanceobserver/index.md index 796f990a5b9c19..fcb4f7b503dc64 100644 --- a/files/zh-cn/web/api/performanceobserver/index.md +++ b/files/zh-cn/web/api/performanceobserver/index.md @@ -27,11 +27,11 @@ slug: Web/API/PerformanceObserver ```js function perf_observer(list, observer) { - // Process the "measure" event - // 处理 "measure" 事件 + // Process the "measure" event + // 处理 "measure" 事件 } var observer2 = new PerformanceObserver(perf_observer); -observer2.observe({entryTypes: ["measure"]}); +observer2.observe({ entryTypes: ["measure"] }); ``` ## 规范 diff --git a/files/zh-cn/web/api/performanceobserver/observe/index.md b/files/zh-cn/web/api/performanceobserver/observe/index.md index 8c006424856503..1dfe60a5faa865 100644 --- a/files/zh-cn/web/api/performanceobserver/observe/index.md +++ b/files/zh-cn/web/api/performanceobserver/observe/index.md @@ -26,14 +26,14 @@ observer.observe(options); /* 写法一 */ //直接往 PerformanceObserver() 入参匿名回调函数,成功 new 了一个 PerformanceObserver 类的,名为 observer 的对象 -var observer = new PerformanceObserver(function(list, obj) { +var observer = new PerformanceObserver(function (list, obj) { var entries = list.getEntries(); - for (var i=0; i < entries.length; i++) { + for (var i = 0; i < entries.length; i++) { //处理“mark”和“frame”事件 } }); //调用 observer 对象的 observe() 方法 -observer.observe({entryTypes: ["mark", "frame"]}); +observer.observe({ entryTypes: ["mark", "frame"] }); /* 写法二 */ @@ -44,7 +44,7 @@ function perf_observer(list, observer) { //再将其传入 PerformanceObserver(),成功 new 了一个 PerformanceObserver 类的,名为 observer2 的对象 var observer2 = new PerformanceObserver(perf_observer); //调用 observer2 对象的 observe() 方法 -observer2.observe({entryTypes: ["measure"]}); +observer2.observe({ entryTypes: ["measure"] }); ``` ## 规范 diff --git a/files/zh-cn/web/api/performanceobserver/performanceobserver/index.md b/files/zh-cn/web/api/performanceobserver/performanceobserver/index.md index 47369ace052e55..8d3adeb6e2056d 100644 --- a/files/zh-cn/web/api/performanceobserver/performanceobserver/index.md +++ b/files/zh-cn/web/api/performanceobserver/performanceobserver/index.md @@ -25,19 +25,19 @@ var observer = new PerformanceObserver(callback); ## 例子 ```js -var observer = new PerformanceObserver(function(list, obj) { +var observer = new PerformanceObserver(function (list, obj) { var entries = list.getEntries(); - for (var i=0; i < entries.length; i++) { + for (var i = 0; i < entries.length; i++) { // Process "mark" and "frame" events } }); -observer.observe({entryTypes: ["mark", "frame"]}); +observer.observe({ entryTypes: ["mark", "frame"] }); function perf_observer(list, observer) { // Process the "measure" event } var observer2 = new PerformanceObserver(perf_observer); -observer2.observe({entryTypes: ["measure"]}); +observer2.observe({ entryTypes: ["measure"] }); ``` ## 规范 diff --git a/files/zh-cn/web/api/performanceobserver/takerecords/index.md b/files/zh-cn/web/api/performanceobserver/takerecords/index.md index 05ad0c9a4b88a8..e6020ea6f66ad4 100644 --- a/files/zh-cn/web/api/performanceobserver/takerecords/index.md +++ b/files/zh-cn/web/api/performanceobserver/takerecords/index.md @@ -24,13 +24,13 @@ var PerformanceEntry[] = performanceObserver.takeRecords(); ## 例子 ```js -var observer = new PerformanceObserver(function(list, obj) { +var observer = new PerformanceObserver(function (list, obj) { var entries = list.getEntries(); - for (var i=0; i < entries.length; i++) { + for (var i = 0; i < entries.length; i++) { // Process "mark" and "frame" events } }); -observer.observe({entryTypes: ["mark", "frame"]}); +observer.observe({ entryTypes: ["mark", "frame"] }); var records = observer.takeRecords(); console.log(records[0].name); console.log(records[0].startTime); diff --git a/files/zh-cn/web/api/performancepainttiming/index.md b/files/zh-cn/web/api/performancepainttiming/index.md index ad8a167236853c..8493278fa80122 100644 --- a/files/zh-cn/web/api/performancepainttiming/index.md +++ b/files/zh-cn/web/api/performancepainttiming/index.md @@ -34,12 +34,18 @@ slug: Web/API/PerformancePaintTiming function showPaintTimings() { if (window.performance) { let performance = window.performance; - let performanceEntries = performance.getEntriesByType('paint'); - performanceEntries.forEach( (performanceEntry, i, entries) => { - console.log("The time to " + performanceEntry.name + " was " + performanceEntry.startTime + " milliseconds."); + let performanceEntries = performance.getEntriesByType("paint"); + performanceEntries.forEach((performanceEntry, i, entries) => { + console.log( + "The time to " + + performanceEntry.name + + " was " + + performanceEntry.startTime + + " milliseconds.", + ); }); } else { - console.log('Performance timing isn\'t supported.'); + console.log("Performance timing isn't supported."); } } ``` diff --git a/files/zh-cn/web/api/permissions/index.md b/files/zh-cn/web/api/permissions/index.md index 9f2a3801fadb68..e3cd013145dd2b 100644 --- a/files/zh-cn/web/api/permissions/index.md +++ b/files/zh-cn/web/api/permissions/index.md @@ -21,10 +21,10 @@ slug: Web/API/Permissions ## Example ```js -navigator.permissions.query({name:'geolocation'}).then(function(result) { - if (result.state === 'granted') { +navigator.permissions.query({ name: "geolocation" }).then(function (result) { + if (result.state === "granted") { showLocalNewsWithGeolocation(); - } else if (result.state === 'prompt') { + } else if (result.state === "prompt") { showButtonToEnableLocalNews(); } // 如果没有此权限则不什么也做 diff --git a/files/zh-cn/web/api/permissions_api/using_the_permissions_api/index.md b/files/zh-cn/web/api/permissions_api/using_the_permissions_api/index.md index 8d0074fb38ed99..0a2fc603126136 100644 --- a/files/zh-cn/web/api/permissions_api/using_the_permissions_api/index.md +++ b/files/zh-cn/web/api/permissions_api/using_the_permissions_api/index.md @@ -48,26 +48,30 @@ You can [在线运行](https://chrisdavidmills.github.io/location-finder-permiss ```js function handlePermission() { - navigator.permissions.query({name:'geolocation'}).then(function(result) { - if (result.state == 'granted') { + navigator.permissions.query({ name: "geolocation" }).then(function (result) { + if (result.state == "granted") { report(result.state); - geoBtn.style.display = 'none'; - } else if (result.state == 'prompt') { + geoBtn.style.display = "none"; + } else if (result.state == "prompt") { report(result.state); - geoBtn.style.display = 'none'; - navigator.geolocation.getCurrentPosition(revealPosition,positionDenied,geoSettings); - } else if (result.state == 'denied') { + geoBtn.style.display = "none"; + navigator.geolocation.getCurrentPosition( + revealPosition, + positionDenied, + geoSettings, + ); + } else if (result.state == "denied") { report(result.state); - geoBtn.style.display = 'inline'; + geoBtn.style.display = "inline"; } - result.onchange = function() { + result.onchange = function () { report(result.state); - } + }; }); } function report(state) { - console.log('Permission ' + state); + console.log("Permission " + state); } handlePermission(); diff --git a/files/zh-cn/web/api/picture-in-picture_api/index.md b/files/zh-cn/web/api/picture-in-picture_api/index.md index 53107d3055f8fc..9ef0fc4f945743 100644 --- a/files/zh-cn/web/api/picture-in-picture_api/index.md +++ b/files/zh-cn/web/api/picture-in-picture_api/index.md @@ -28,7 +28,7 @@ slug: Web/API/Picture-in-Picture_API ## 属性 -*画中画 API 添加了* {{DOMxRef("HTMLVideoElement")}}、{{DOMxRef("Document")}} 和 {{DOMxRef("ShadowRoot")}} 接口的属性,这些属性用于决定浮动的视频窗口是否是受支持和可用的、当前画中画模式是否处于激活状态并且哪个视频是浮动的。 +_画中画 API 添加了_ {{DOMxRef("HTMLVideoElement")}}、{{DOMxRef("Document")}} 和 {{DOMxRef("ShadowRoot")}} 接口的属性,这些属性用于决定浮动的视频窗口是否是受支持和可用的、当前画中画模式是否处于激活状态并且哪个视频是浮动的。 ### HTMLVideoElement 接口的属性 @@ -79,7 +79,7 @@ _画中画 API 定义了三个事件,它们可以用来检测画中画模式 ```js function togglePictureInPicture() { if (document.pictureInPictureElement) { - document.exitPictureInPicture(); + document.exitPictureInPicture(); } else { if (document.pictureInPictureEnabled) { video.requestPictureInPicture(); diff --git a/files/zh-cn/web/api/pictureinpicturewindow/index.md b/files/zh-cn/web/api/pictureinpicturewindow/index.md index 2d2193ddf52479..4ed4de46792ea4 100644 --- a/files/zh-cn/web/api/pictureinpicturewindow/index.md +++ b/files/zh-cn/web/api/pictureinpicturewindow/index.md @@ -39,13 +39,15 @@ const video = document.querySelector("video"); function printPipWindowDimensions(evt) { const pipWindow = evt.target; - console.log(`The floating window dimensions are: ${pipWindow.width}x${pipWindow.height}px`); + console.log( + `The floating window dimensions are: ${pipWindow.width}x${pipWindow.height}px`, + ); // will print: // The floating window dimensions are: 640x360px } -button.onclick = function() { - video.requestPictureInPicture().then(pictureInPictureWindow => { +button.onclick = function () { + video.requestPictureInPicture().then((pictureInPictureWindow) => { pictureInPictureWindow.onresize = printPipWindowDimensions; }); }; diff --git a/files/zh-cn/web/api/plugin/index.md b/files/zh-cn/web/api/plugin/index.md index 41b3f27de97812..72ca20797f1664 100644 --- a/files/zh-cn/web/api/plugin/index.md +++ b/files/zh-cn/web/api/plugin/index.md @@ -14,11 +14,11 @@ slug: Web/API/Plugin ## 属性 -| 名称 | 描述 | 返回值类型 | 兼容性 | -| -------------------------------------------- | ----------------------------------- | -------------------------------- | -------------------------------- | +| 名称 | 描述 | 返回值类型 | 兼容性 | +| --------------------------------- | ----------------------------------- | ------------------------ | -------------------------------- | | {{domxref("Plugin.description")}} | 一个人类可读的插件描述。 **只读。** | {{domxref("DOMString")}} | DOM 0 | -| {{domxref("Plugin.filename")}} | 插件文件名。**只读。** | {{domxref("DOMString")}} | DOM 0 | -| {{domxref("Plugin.name")}} | 插件名。**只读。** | {{domxref("DOMString")}} | DOM 0 | +| {{domxref("Plugin.filename")}} | 插件文件名。**只读。** | {{domxref("DOMString")}} | DOM 0 | +| {{domxref("Plugin.name")}} | 插件名。**只读。** | {{domxref("DOMString")}} | DOM 0 | | {{domxref("Plugin.version")}} | 插件版本号字符串。**只读。** | {{domxref("DOMString")}} | Gecko browsers only (Firefox 4+) | ## 方法 diff --git a/files/zh-cn/web/api/pointer_events/index.md b/files/zh-cn/web/api/pointer_events/index.md index 3e1ee282de7a42..db38c88ac8cc21 100644 --- a/files/zh-cn/web/api/pointer_events/index.md +++ b/files/zh-cn/web/api/pointer_events/index.md @@ -55,18 +55,18 @@ slug: Web/API/Pointer_events 指针事件有始终不同的事件类型,其中其中在鼠标事件中有相对应的语义话表示 (`down, up, move, over, out, enter, leave`)。以下是每个事件类型及所对应的{{domxref("GlobalEventHandlers","Global Event Handler")}}的基本介绍。 -| 事件 | 描述 | -| --------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| {{domxref('Element/pointerover_event', 'pointerover')}} | 当定点设备进入某个元素的[命中检测](#命中检测) 范围时触发。 | -| {{domxref('Element/pointerenter_event', 'pointerenter')}} | 当定点设备进入某个元素或其子元素的[命中检测](#命中检测)范围时,或做为某一类不支悬停(hover)状态的设备所触发的 poinerdown 事件的后续事件时所触发。(详情可见 pointerdown 事件类型)。 | -| {{domxref('Element/pointerdown_event', 'pointerdown')}} | 当某指针得以激活时触发。 | -| {{domxref('Element/pointermove_event', 'pointermove')}} | 当某指针改变其坐标时触发。 | -| {{domxref('Element/pointerup_event', 'pointerup')}} | 当某指针不再活跃时触发。 | -| {{domxref('Element/pointercancel_event', 'pointercancel')}} | 当浏览器认为某指针不会再生成新的后续事件时触发(例如某设备不再活跃) | +| 事件 | 描述 | +| --------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| {{domxref('Element/pointerover_event', 'pointerover')}} | 当定点设备进入某个元素的[命中检测](#命中检测) 范围时触发。 | +| {{domxref('Element/pointerenter_event', 'pointerenter')}} | 当定点设备进入某个元素或其子元素的[命中检测](#命中检测)范围时,或做为某一类不支悬停(hover)状态的设备所触发的 poinerdown 事件的后续事件时所触发。(详情可见 pointerdown 事件类型)。 | +| {{domxref('Element/pointerdown_event', 'pointerdown')}} | 当某指针得以激活时触发。 | +| {{domxref('Element/pointermove_event', 'pointermove')}} | 当某指针改变其坐标时触发。 | +| {{domxref('Element/pointerup_event', 'pointerup')}} | 当某指针不再活跃时触发。 | +| {{domxref('Element/pointercancel_event', 'pointercancel')}} | 当浏览器认为某指针不会再生成新的后续事件时触发(例如某设备不再活跃) | | {{domxref('Element/pointerout_event', 'pointerout')}} | 可能由若干原因触发该事件,包括:定位设备移出了某[命中检测](#命中检测)的边界;不支持悬浮状态的设备发生 pointerup 事件(见 pointerup 事件);作为 pointercancel 事件的后续事件(见 pointercancel 事件);当数位板检测到数位笔离开了悬浮区域时。 | -| {{domxref('Element/pointerleave_event', 'pointerleave')}} | 当定点设备移出某元素的[命中检测](#命中检测)边界时触发。对于笔形设备来说,当数位板检测到笔移出了悬浮范围时触发。 | -| {{domxref('Element/gotpointercapture_event', 'gotpointercapture')}} | 当某元素接受到一个指针捕捉时触发。 | -| {{domxref('Element/lostpointercapture_event', 'lostpointercapture')}} | 当针对某个指针的指针捕捉得到释放时触发。 | +| {{domxref('Element/pointerleave_event', 'pointerleave')}} | 当定点设备移出某元素的[命中检测](#命中检测)边界时触发。对于笔形设备来说,当数位板检测到笔移出了悬浮范围时触发。 | +| {{domxref('Element/gotpointercapture_event', 'gotpointercapture')}} | 当某元素接受到一个指针捕捉时触发。 | +| {{domxref('Element/lostpointercapture_event', 'lostpointercapture')}} | 当针对某个指针的指针捕捉得到释放时触发。 | ### Element 接口扩展 @@ -90,19 +90,19 @@ slug: Web/API/Pointer_events ```html -
Touch me ...
+
Touch me ...
``` @@ -172,7 +172,7 @@ slug: Web/API/Pointer_events process_touch(ev); break; default: - console.log("pointerType " + ev.pointerType + " is Not suported"); + console.log("pointerType " + ev.pointerType + " is Not suported"); } // Call the tilt handler @@ -186,13 +186,13 @@ slug: Web/API/Pointer_events } function init() { - var el=document.getElementById("target"); + var el = document.getElementById("target"); // Register pointerdown handler el.onpointerdown = down_handler; } -
Touch me ...
+
Touch me ...
``` @@ -228,21 +228,21 @@ slug: Web/API/Pointer_events ```html - - -
Touch me ...
- + + +
Touch me ...
+ ``` @@ -252,26 +252,26 @@ slug: Web/API/Pointer_events -
Touch me ...
+
Touch me ...
``` @@ -287,7 +287,7 @@ CSS 属性{{cssxref("touch-action")}}被用来指明浏览器是否应当对某 ```html -
Can't touch this ...
+
Can't touch this ...
``` diff --git a/files/zh-cn/web/api/pointer_lock_api/index.md b/files/zh-cn/web/api/pointer_lock_api/index.md index 15fab95a2972fb..b1b68a8fee6ed5 100644 --- a/files/zh-cn/web/api/pointer_lock_api/index.md +++ b/files/zh-cn/web/api/pointer_lock_api/index.md @@ -117,9 +117,10 @@ Pointer lock API 还扩展了 `document` 接口,添加了一个新的属性和 `pointerLockElement` 属性适用于确定当前是否有被指针锁定的元素(例如,用来做一个布尔检查),以及当有元素被锁定时获取该元素的一个引用。下面是这两种用法的一个例子: ```js -document.pointerLockElement = document.pointerLockElement || - document.mozPointerLockElement || - document.webkitPointerLockElement; +document.pointerLockElement = + document.pointerLockElement || + document.mozPointerLockElement || + document.webkitPointerLockElement; // 1) 用于布尔检查 -- 我们被指针锁定了吗? if (!!document.pointerLockElement) { @@ -137,14 +138,16 @@ if (document.pointerLockElement === someElement) { `document` 的 `exitPointerLock` 方法被用来退出指针锁定,而且和 requestPointerLock 一样,使用 `pointerlockchange` 和 `pointerlockerror`事件以异步方式工作: ```js -document.exitPointerLock = document.exitPointerLock || - document.mozExitPointerLock || - document.webkitExitPointerLock; +document.exitPointerLock = + document.exitPointerLock || + document.mozExitPointerLock || + document.webkitExitPointerLock; function pointerLockChange() { - document.pointerLockElement = document.pointerLockElement || - document.mozPointerLockElement || - document.webkitPointerLockElement; + document.pointerLockElement = + document.pointerLockElement || + document.mozPointerLockElement || + document.webkitPointerLockElement; if (!!document.pointerLockElement) { console.log("目前还是被锁定。"); @@ -153,9 +156,9 @@ function pointerLockChange() { } } -document.addEventListener('pointerlockchange', pointerLockChange, false); -document.addEventListener('mozpointerlockchange', pointerLockChange, false); -document.addEventListener('webkitpointerlockchange', pointerLockChange, false); +document.addEventListener("pointerlockchange", pointerLockChange, false); +document.addEventListener("mozpointerlockchange", pointerLockChange, false); +document.addEventListener("webkitpointerlockchange", pointerLockChange, false); // 试图解除锁定 document.exitPointerLock(); diff --git a/files/zh-cn/web/api/progressevent/index.md b/files/zh-cn/web/api/progressevent/index.md index 43f25dd700d9f2..754accd56334de 100644 --- a/files/zh-cn/web/api/progressevent/index.md +++ b/files/zh-cn/web/api/progressevent/index.md @@ -38,18 +38,18 @@ _同时继承它的父元素 {{domxref("Event")}} 的方法。_ ```js var progressBar = document.getElementById("p"), - client = new XMLHttpRequest() -client.open("GET", "magical-unicorns") -client.onprogress = function(pe) { - if(pe.lengthComputable) { - progressBar.max = pe.total - progressBar.value = pe.loaded + client = new XMLHttpRequest(); +client.open("GET", "magical-unicorns"); +client.onprogress = function (pe) { + if (pe.lengthComputable) { + progressBar.max = pe.total; + progressBar.value = pe.loaded; } -} -client.onloadend = function(pe) { - progressBar.value = pe.loaded -} -client.send() +}; +client.onloadend = function (pe) { + progressBar.value = pe.loaded; +}; +client.send(); ``` ## 规范 diff --git a/files/zh-cn/web/api/progressevent/progressevent/index.md b/files/zh-cn/web/api/progressevent/progressevent/index.md index 4884232c0d0461..72dea6118f9fe9 100644 --- a/files/zh-cn/web/api/progressevent/progressevent/index.md +++ b/files/zh-cn/web/api/progressevent/progressevent/index.md @@ -10,8 +10,8 @@ slug: Web/API/ProgressEvent/ProgressEvent ## 语法 ```js -new ProgressEvent(type) -new ProgressEvent(type, options) +new ProgressEvent(type); +new ProgressEvent(type, options); ``` ### 参数 diff --git a/files/zh-cn/web/api/promiserejectionevent/index.md b/files/zh-cn/web/api/promiserejectionevent/index.md index 6aaa8c2de4ee5f..56c1bee33dd6a0 100644 --- a/files/zh-cn/web/api/promiserejectionevent/index.md +++ b/files/zh-cn/web/api/promiserejectionevent/index.md @@ -35,9 +35,9 @@ _没有特定的方法; 从它的父级 {{domxref("Event")}}继承方法。_ ## 示例 ```js -window.onunhandledrejection = function(e) { +window.onunhandledrejection = function (e) { console.log(e.reason); -} +}; ``` ## 规范 diff --git a/files/zh-cn/web/api/promiserejectionevent/promise/index.md b/files/zh-cn/web/api/promiserejectionevent/promise/index.md index fce56b3e927294..0e54abea84f1ae 100644 --- a/files/zh-cn/web/api/promiserejectionevent/promise/index.md +++ b/files/zh-cn/web/api/promiserejectionevent/promise/index.md @@ -24,15 +24,14 @@ promise = PromiseRejectionEvent.promise {{domxref("event.preventDefault()")}} 用来表明该 promise 已被处理 ```js -window.onunhandledrejection = function(event) { +window.onunhandledrejection = function (event) { if (event.reason.code && event.reason.code == "Module not ready") { - window.requestIdleCallback(function(deadline) { - loadModule(event.reason.moduleName) - .then(performStartup); + window.requestIdleCallback(function (deadline) { + loadModule(event.reason.moduleName).then(performStartup); }); event.preventDefault(); } -} +}; ``` ## Specifications diff --git a/files/zh-cn/web/api/promiserejectionevent/promiserejectionevent/index.md b/files/zh-cn/web/api/promiserejectionevent/promiserejectionevent/index.md index 26418e9b9717b0..ec6616cfa6f875 100644 --- a/files/zh-cn/web/api/promiserejectionevent/promiserejectionevent/index.md +++ b/files/zh-cn/web/api/promiserejectionevent/promiserejectionevent/index.md @@ -30,9 +30,9 @@ _`PromiseRejectionEvent()` 构造函数继承了 {{domxref("Event.Event", "Event ## 例子 ```js -var myRejectionEvent = new PromiseRejectionEvent('unhandledrejection', { - promise : myPromise, - reason : 'My house is on fire' +var myRejectionEvent = new PromiseRejectionEvent("unhandledrejection", { + promise: myPromise, + reason: "My house is on fire", }); ``` diff --git a/files/zh-cn/web/api/pushmanager/getsubscription/index.md b/files/zh-cn/web/api/pushmanager/getsubscription/index.md index eeec325b078baf..2028412e1a2ba2 100644 --- a/files/zh-cn/web/api/pushmanager/getsubscription/index.md +++ b/files/zh-cn/web/api/pushmanager/getsubscription/index.md @@ -29,35 +29,36 @@ A {{jsxref("Promise")}} that resolves to a {{domxref("PushSubscription")}} objec ```js // We need the service worker registration to check for a subscription - navigator.serviceWorker.ready.then(function(serviceWorkerRegistration) { - // Do we already have a push message subscription? - serviceWorkerRegistration.pushManager.getSubscription() - .then(function(subscription) { - // Enable any UI which subscribes / unsubscribes from - // push messages. - var pushButton = document.querySelector('.js-push-button'); - pushButton.disabled = false; - - if (!subscription) { - // We aren’t subscribed to push, so set UI - // to allow the user to enable push - return; - } - - // Keep your server in sync with the latest subscriptionId - sendSubscriptionToServer(subscription); - - showCurlCommand(subscription); - - // Set your UI to show they have subscribed for - // push messages - pushButton.textContent = 'Disable Push Messages'; - isPushEnabled = true; - }) - .catch(function(err) { - window.Demo.debug.log('Error during getSubscription()', err); - }); - }); +navigator.serviceWorker.ready.then(function (serviceWorkerRegistration) { + // Do we already have a push message subscription? + serviceWorkerRegistration.pushManager + .getSubscription() + .then(function (subscription) { + // Enable any UI which subscribes / unsubscribes from + // push messages. + var pushButton = document.querySelector(".js-push-button"); + pushButton.disabled = false; + + if (!subscription) { + // We aren’t subscribed to push, so set UI + // to allow the user to enable push + return; + } + + // Keep your server in sync with the latest subscriptionId + sendSubscriptionToServer(subscription); + + showCurlCommand(subscription); + + // Set your UI to show they have subscribed for + // push messages + pushButton.textContent = "Disable Push Messages"; + isPushEnabled = true; + }) + .catch(function (err) { + window.Demo.debug.log("Error during getSubscription()", err); + }); +}); ``` ## 规范 diff --git a/files/zh-cn/web/api/pushmanager/index.md b/files/zh-cn/web/api/pushmanager/index.md index 4100228a498ba6..50a201150d6ccf 100644 --- a/files/zh-cn/web/api/pushmanager/index.md +++ b/files/zh-cn/web/api/pushmanager/index.md @@ -38,22 +38,24 @@ _None._ ## 示例 ```js -this.onpush = function(event) { +this.onpush = function (event) { console.log(event.data); // 这里我们可以将数据写入 IndexedDB,发送给其他 window 对象,或者显示一个通知 -} +}; -navigator.serviceWorker.register('serviceworker.js').then( - function(serviceWorkerRegistration) { +navigator.serviceWorker + .register("serviceworker.js") + .then(function (serviceWorkerRegistration) { serviceWorkerRegistration.pushManager.subscribe().then( - function(pushSubscription) { + function (pushSubscription) { console.log(pushSubscription.subscriptionId); console.log(pushSubscription.endpoint); // 现在我们已经获取到了服务器需要的 push 订阅信息,我们可以使用 XHR 将它们发送给服务器 - }, function(error) { + }, + function (error) { // 在开发环境下打印错误是很有帮助的。在生产环境下,将错误上报到服务器也是十分必要的 console.log(error); - } + }, ); }); ``` diff --git a/files/zh-cn/web/api/pushmessagedata/index.md b/files/zh-cn/web/api/pushmessagedata/index.md index a1ad96f92ed085..3fc75c0020b980 100644 --- a/files/zh-cn/web/api/pushmessagedata/index.md +++ b/files/zh-cn/web/api/pushmessagedata/index.md @@ -29,23 +29,28 @@ None. In our [Push API Demo](https://github.com/chrisdavidmills/push-api-demo), we send JSON objects via push messages from our server by first converting them to strings via {{jsxref("JSON.stringify()")}} ([see server.js example](https://github.com/chrisdavidmills/push-api-demo/blob/gh-pages/server.js#L30-L34)): ```js -webPush.sendNotification(subscriber[2], 200, obj.key, JSON.stringify({ - action: 'chatMsg', - name: obj.name, - msg: obj.msg -})); +webPush.sendNotification( + subscriber[2], + 200, + obj.key, + JSON.stringify({ + action: "chatMsg", + name: obj.name, + msg: obj.msg, + }), +); ``` When the message reaches the [service worker](https://github.com/chrisdavidmills/push-api-demo/blob/gh-pages/sw.js), we [convert the data back to a JSON object](https://github.com/chrisdavidmills/push-api-demo/blob/gh-pages/sw.js#L4) using {{domxref("PushMessageData.json()")}} before working out what to do with it next: ```js -self.addEventListener('push', function(event) { +self.addEventListener("push", function (event) { var obj = event.data.json(); - if(obj.action === 'subscribe' || obj.action === 'unsubscribe') { + if (obj.action === "subscribe" || obj.action === "unsubscribe") { fireNotification(obj, event); port.postMessage(obj); - } else if(obj.action === 'init' || obj.action === 'chatMsg') { + } else if (obj.action === "init" || obj.action === "chatMsg") { port.postMessage(obj); } }); diff --git a/files/zh-cn/web/api/pushmessagedata/json/index.md b/files/zh-cn/web/api/pushmessagedata/json/index.md index 3298ec22d0b16d..b69b3899d73df1 100644 --- a/files/zh-cn/web/api/pushmessagedata/json/index.md +++ b/files/zh-cn/web/api/pushmessagedata/json/index.md @@ -24,7 +24,7 @@ A [JSON](/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/JSON) object. ## Examples ```js -self.addEventListener('push', function(event) { +self.addEventListener("push", function (event) { var jsonObj = event.data.json(); // do something with your JSON diff --git a/files/zh-cn/web/api/queuemicrotask/index.md b/files/zh-cn/web/api/queuemicrotask/index.md index 0f8762c3cda9f3..f2c72f10b67743 100644 --- a/files/zh-cn/web/api/queuemicrotask/index.md +++ b/files/zh-cn/web/api/queuemicrotask/index.md @@ -35,7 +35,7 @@ queueMicrotask(() => {/* ... */}); ```js queueMicrotask(() => { // 函数的内容 -}) +}); ``` 来自 [`queueMicrotask` 的规范文档:](https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#microtask-queuing) diff --git a/files/zh-cn/web/api/range/collapsed/index.md b/files/zh-cn/web/api/range/collapsed/index.md index f2022679e90b9a..61968f103ca307 100644 --- a/files/zh-cn/web/api/range/collapsed/index.md +++ b/files/zh-cn/web/api/range/collapsed/index.md @@ -20,8 +20,8 @@ isCollapsed = range.collapsed; ```js var range = document.createRange(); -range.setStart(startNode,startOffset); -range.setEnd(endNode,endOffset); +range.setStart(startNode, startOffset); +range.setEnd(endNode, endOffset); isCollapsed = range.collapsed; ``` diff --git a/files/zh-cn/web/api/range/commonancestorcontainer/index.md b/files/zh-cn/web/api/range/commonancestorcontainer/index.md index 26e337a6864e21..547d2a2a691699 100644 --- a/files/zh-cn/web/api/range/commonancestorcontainer/index.md +++ b/files/zh-cn/web/api/range/commonancestorcontainer/index.md @@ -22,8 +22,8 @@ rangeAncestor = range.commonAncestorContainer; ```js var range = document.createRange(); -range.setStart(startNode,startOffset); -range.setEnd(endNode,endOffset); +range.setStart(startNode, startOffset); +range.setEnd(endNode, endOffset); rangeAncestor = range.commonAncestorContainer; ``` diff --git a/files/zh-cn/web/api/range/endcontainer/index.md b/files/zh-cn/web/api/range/endcontainer/index.md index c89a816186aa9f..21795938a04727 100644 --- a/files/zh-cn/web/api/range/endcontainer/index.md +++ b/files/zh-cn/web/api/range/endcontainer/index.md @@ -18,8 +18,8 @@ endRangeNode = range.endContainer; ```js var range = document.createRange(); -range.setStart(startNode,startOffset); -range.setEnd(endNode,endOffset); +range.setStart(startNode, startOffset); +range.setEnd(endNode, endOffset); endRangeNode = range.endContainer; ``` diff --git a/files/zh-cn/web/api/range/endoffset/index.md b/files/zh-cn/web/api/range/endoffset/index.md index 59d047d00cbc94..28695a916f895e 100644 --- a/files/zh-cn/web/api/range/endoffset/index.md +++ b/files/zh-cn/web/api/range/endoffset/index.md @@ -20,8 +20,8 @@ endRangeOffset = range.endOffset; ```js var range = document.createRange(); -range.setStart(startNode,startOffset); -range.setEnd(endNode,endOffset); +range.setStart(startNode, startOffset); +range.setEnd(endNode, endOffset); endRangeOffset = range.endOffset; ``` diff --git a/files/zh-cn/web/api/range/getboundingclientrect/index.md b/files/zh-cn/web/api/range/getboundingclientrect/index.md index a7f15f7456ee70..43c58721bffcc7 100644 --- a/files/zh-cn/web/api/range/getboundingclientrect/index.md +++ b/files/zh-cn/web/api/range/getboundingclientrect/index.md @@ -21,7 +21,12 @@ boundingRect = range.getBoundingClientRect() ```html
-

This example positions a "highlight" rectangle behind the contents of a range. The range's content starts here and continues on until it ends here. The bounding client rectangle contains everything selected in the range.

+

+ This example positions a "highlight" rectangle behind the contents of a range. + The range's content starts here and continues on until it + ends here. The bounding client rectangle contains everything selected + in the range. +

``` ### CSS @@ -42,11 +47,11 @@ p { ```js const range = document.createRange(); -range.setStartBefore(document.getElementsByTagName('b').item(0), 0); -range.setEndAfter(document.getElementsByTagName('b').item(1), 0); +range.setStartBefore(document.getElementsByTagName("b").item(0), 0); +range.setEndAfter(document.getElementsByTagName("b").item(1), 0); const clientRect = range.getBoundingClientRect(); -const highlight = document.getElementById('highlight'); +const highlight = document.getElementById("highlight"); highlight.style.left = `${clientRect.x}px`; highlight.style.top = `${clientRect.y}px`; highlight.style.width = `${clientRect.width}px`; diff --git a/files/zh-cn/web/api/range/range/index.md b/files/zh-cn/web/api/range/range/index.md index e0527e8aa61b52..9cf237ab1c5b6f 100644 --- a/files/zh-cn/web/api/range/range/index.md +++ b/files/zh-cn/web/api/range/range/index.md @@ -29,7 +29,7 @@ range = new Range() ### JavaScript ```js -const paragraphs = document.querySelectorAll('p'); +const paragraphs = document.querySelectorAll("p"); // 创建 Range 对象 const range = new Range(); diff --git a/files/zh-cn/web/api/range/setstart/index.md b/files/zh-cn/web/api/range/setstart/index.md index 739520841abc26..e18ae14ba315fc 100644 --- a/files/zh-cn/web/api/range/setstart/index.md +++ b/files/zh-cn/web/api/range/setstart/index.md @@ -30,7 +30,7 @@ range.setStart(startNode, startOffset); var range = document.createRange(); var startNode = document.getElementsByTagName("p").item(2); var startOffset = 0; -range.setStart(startNode,startOffset); +range.setStart(startNode, startOffset); ``` ## 规范 diff --git a/files/zh-cn/web/api/range/startcontainer/index.md b/files/zh-cn/web/api/range/startcontainer/index.md index 70f945389d8dbf..1225292673d1d1 100644 --- a/files/zh-cn/web/api/range/startcontainer/index.md +++ b/files/zh-cn/web/api/range/startcontainer/index.md @@ -15,8 +15,8 @@ startRangeNode = range.startContainer; ```js range = document.createRange(); -range.setStart(startNode,startOffset); -range.setEnd(endNode,endOffset); +range.setStart(startNode, startOffset); +range.setEnd(endNode, endOffset); startRangeNode = range.startContainer; ``` diff --git a/files/zh-cn/web/api/range/startoffset/index.md b/files/zh-cn/web/api/range/startoffset/index.md index 000145ae14f81e..3a8a503e57af24 100644 --- a/files/zh-cn/web/api/range/startoffset/index.md +++ b/files/zh-cn/web/api/range/startoffset/index.md @@ -21,8 +21,8 @@ startRangeOffset = range.startOffset; ```js range = document.createRange(); -range.setStart(startNode,startOffset); -range.setEnd(endNode,endOffset); +range.setStart(startNode, startOffset); +range.setEnd(endNode, endOffset); startRangeOffset = range.startOffset; ``` diff --git a/files/zh-cn/web/api/readablestream/cancel/index.md b/files/zh-cn/web/api/readablestream/cancel/index.md index 20ddd9a02bdee8..30ab0ea16b8d2a 100644 --- a/files/zh-cn/web/api/readablestream/cancel/index.md +++ b/files/zh-cn/web/api/readablestream/cancel/index.md @@ -12,8 +12,8 @@ cancel 用于在不再需要来自它的任何数据的情况下(即使仍有 ## 语法 ```js -cancel() -cancel(reason) +cancel(); +cancel(reason); ``` ### 参数 @@ -40,52 +40,60 @@ var searchTerm = "service workers"; var contextBefore = 30; var contextAfter = 30; var caseInsensitive = true; -var url = 'https://html.spec.whatwg.org/'; +var url = "https://html.spec.whatwg.org/"; console.log(`Searching '${url}' for '${searchTerm}'`); -fetch(url).then(response => { - console.log('Received headers'); - var decoder = new TextDecoder(); - var reader = response.body.getReader(); - var toMatch = caseInsensitive ? searchTerm.toLowerCase() : searchTerm; - var bufferSize = Math.max(toMatch.length - 1, contextBefore); - var bytesReceived = 0; - var buffer = ''; - var matchFoundAt = -1; - return reader.read().then(function process(result) { - if (result.done) { - console.log('Failed to find match'); - return; - } - bytesReceived += result.value.length; - console.log(`Received ${bytesReceived} bytes of data so far`); - buffer += decoder.decode(result.value, {stream: true}); - // already found match & just context-gathering? - if (matchFoundAt === -1) { - matchFoundAt = (caseInsensitive ? buffer.toLowerCase() : buffer).indexOf(toMatch); - } - if (matchFoundAt === -1) { - buffer = buffer.slice(-bufferSize); - } - else if (buffer.slice(matchFoundAt + toMatch.length).length >= contextAfter) { - console.log("Here's the match:") - console.log(buffer.slice( - Math.max(0, matchFoundAt - contextBefore), - matchFoundAt + toMatch.length + contextAfter - )); - console.log("Cancelling fetch"); - reader.cancel(); - return; - } - else { - console.log('Found match, but need more context…'); - } - // 保持读取 - return reader.read().then(process); +fetch(url) + .then((response) => { + console.log("Received headers"); + var decoder = new TextDecoder(); + var reader = response.body.getReader(); + var toMatch = caseInsensitive ? searchTerm.toLowerCase() : searchTerm; + var bufferSize = Math.max(toMatch.length - 1, contextBefore); + var bytesReceived = 0; + var buffer = ""; + var matchFoundAt = -1; + return reader.read().then(function process(result) { + if (result.done) { + console.log("Failed to find match"); + return; + } + bytesReceived += result.value.length; + console.log(`Received ${bytesReceived} bytes of data so far`); + buffer += decoder.decode(result.value, { stream: true }); + // already found match & just context-gathering? + if (matchFoundAt === -1) { + matchFoundAt = ( + caseInsensitive ? buffer.toLowerCase() : buffer + ).indexOf(toMatch); + } + if (matchFoundAt === -1) { + buffer = buffer.slice(-bufferSize); + } else if ( + buffer.slice(matchFoundAt + toMatch.length).length >= contextAfter + ) { + console.log("Here's the match:"); + console.log( + buffer.slice( + Math.max(0, matchFoundAt - contextBefore), + matchFoundAt + toMatch.length + contextAfter, + ), + ); + console.log("Cancelling fetch"); + reader.cancel(); + return; + } else { + console.log("Found match, but need more context…"); + } + // 保持读取 + return reader.read().then(process); + }); + }) + .catch((err) => { + console.log( + "Something went wrong. See devtools for details. Does the response lack CORS headers?", + ); + throw err; }); -}).catch(err => { - console.log("Something went wrong. See devtools for details. Does the response lack CORS headers?"); - throw err; -}); ``` ## 规范 diff --git a/files/zh-cn/web/api/readablestream/getreader/index.md b/files/zh-cn/web/api/readablestream/getreader/index.md index 0a765566a6dcf7..f37dd936974d70 100644 --- a/files/zh-cn/web/api/readablestream/getreader/index.md +++ b/files/zh-cn/web/api/readablestream/getreader/index.md @@ -10,8 +10,8 @@ slug: Web/API/ReadableStream/getReader ## 语法 ```js -getReader() -getReader(mode) +getReader(); +getReader(mode); ``` ### 参数 @@ -56,8 +56,12 @@ function fetchStream() { // value for fetch streams is a Uint8Array charsReceived += value.length; const chunk = value; - let listItem = document.createElement('li'); - listItem.textContent = 'Received ' + charsReceived + ' characters so far. Current chunk = ' + chunk; + let listItem = document.createElement("li"); + listItem.textContent = + "Received " + + charsReceived + + " characters so far. Current chunk = " + + chunk; list2.appendChild(listItem); result += chunk; diff --git a/files/zh-cn/web/api/readablestream/index.md b/files/zh-cn/web/api/readablestream/index.md index cf4e5d7c6c2abd..537ccc690d7912 100644 --- a/files/zh-cn/web/api/readablestream/index.md +++ b/files/zh-cn/web/api/readablestream/index.md @@ -39,7 +39,7 @@ slug: Web/API/ReadableStream 它演示了 {{domxref("ReadableStream")}} 与 {{domxref("Uint8Array")}} 的协同用法。 ```js -fetch('https://www.example.org') +fetch("https://www.example.org") .then((response) => response.body) .then((rb) => { const reader = rb.getReader(); @@ -51,7 +51,7 @@ fetch('https://www.example.org') reader.read().then(({ done, value }) => { // If there is no more data to read if (done) { - console.log('done', done); + console.log("done", done); controller.close(); return; } @@ -68,7 +68,7 @@ fetch('https://www.example.org') }) .then((stream) => // Respond with our stream - new Response(stream, { headers: { 'Content-Type': 'text/html' } }).text() + new Response(stream, { headers: { "Content-Type": "text/html" } }).text(), ) .then((result) => { // Do things with result diff --git a/files/zh-cn/web/api/readablestream/pipethrough/index.md b/files/zh-cn/web/api/readablestream/pipethrough/index.md index ad33f1d0fbb72c..08f2c704575b29 100644 --- a/files/zh-cn/web/api/readablestream/pipethrough/index.md +++ b/files/zh-cn/web/api/readablestream/pipethrough/index.md @@ -12,13 +12,14 @@ slug: Web/API/ReadableStream/pipeThrough ## 语法 ```js -pipeThrough(transformStream) -pipeThrough(transformStream, options) +pipeThrough(transformStream); +pipeThrough(transformStream, options); ``` ### 参数 - `transformStream` + - : 由一对可读流和可写流组成的 {{domxref("TransformStream")}}(或者结构为 `{writable, readable}` 的对象),它们共同工作以对数据进行转换。`writable` 流写入的数据在某些状态下可以被 `readable` 流读取。例如,向 {{domxref("TextDecoder")}} 写入字节并从中读取字符串,而视频解码器则是写入编码的字节数据,并从中读取解压后的视频帧。 - `options` {{optional_inline}} @@ -51,13 +52,13 @@ pipeThrough(transformStream, options) ```js // 通过 fetch 获取原始图像 -fetch('png-logo.png') -// 将响应的 body 作为 ReadableStream -.then(response => response.body) -.then(rs => logReadableStream('Fetch Response Stream', rs)) -// 从原始图像创造一个 PNG 的灰度图像 -.then(body => body.pipeThrough(new PNGTransformStream())) -.then(rs => logReadableStream('PNG Chunk Stream', rs)) +fetch("png-logo.png") + // 将响应的 body 作为 ReadableStream + .then((response) => response.body) + .then((rs) => logReadableStream("Fetch Response Stream", rs)) + // 从原始图像创造一个 PNG 的灰度图像 + .then((body) => body.pipeThrough(new PNGTransformStream())) + .then((rs) => logReadableStream("PNG Chunk Stream", rs)); ``` ## 规范 diff --git a/files/zh-cn/web/api/readablestream/pipeto/index.md b/files/zh-cn/web/api/readablestream/pipeto/index.md index 6149f5bb7d763e..0695c235b6fa19 100644 --- a/files/zh-cn/web/api/readablestream/pipeto/index.md +++ b/files/zh-cn/web/api/readablestream/pipeto/index.md @@ -12,13 +12,14 @@ slug: Web/API/ReadableStream/pipeTo ## 语法 ```js -pipeTo(destination) -pipeTo(destination, options) +pipeTo(destination); +pipeTo(destination, options); ``` ### 参数 - `destination` + - : 充当 {{domxref("ReadableStream")}} 最终目标的 {{domxref("WritableStream")}}。 - `options` {{optional_inline}} @@ -47,11 +48,11 @@ pipeTo(destination, options) ```js // 获取原始图像 -fetch('png-logo.png') -// 取回响应的 body 属性,该属性继承 ReadableStream -.then(response => response.body) -.then(body => body.pipeThrough(new PNGTransformStream())) -.then(rs => rs.pipeTo(new FinalDestinationStream())) +fetch("png-logo.png") + // 取回响应的 body 属性,该属性继承 ReadableStream + .then((response) => response.body) + .then((body) => body.pipeThrough(new PNGTransformStream())) + .then((rs) => rs.pipeTo(new FinalDestinationStream())); ``` ## 规范 diff --git a/files/zh-cn/web/api/readablestream/readablestream/index.md b/files/zh-cn/web/api/readablestream/readablestream/index.md index e8451794c49abd..c9f8f2c11f9f80 100644 --- a/files/zh-cn/web/api/readablestream/readablestream/index.md +++ b/files/zh-cn/web/api/readablestream/readablestream/index.md @@ -70,16 +70,16 @@ const stream = new ReadableStream({ controller.enqueue(string); // show it on the screen - let listItem = document.createElement('li'); + let listItem = document.createElement("li"); listItem.textContent = string; list1.appendChild(listItem); }, 1000); - button.addEventListener('click', function() { + button.addEventListener("click", function () { clearInterval(interval); fetchStream(); controller.close(); - }) + }); }, pull(controller) { // We don't really need a pull in this example @@ -88,7 +88,7 @@ const stream = new ReadableStream({ // This is called if the reader cancels, // so we should stop generating strings clearInterval(interval); - } + }, }); ``` diff --git a/files/zh-cn/web/api/readablestream/tee/index.md b/files/zh-cn/web/api/readablestream/tee/index.md index 27cbd14ea24ed8..2d91e5020e250c 100644 --- a/files/zh-cn/web/api/readablestream/tee/index.md +++ b/files/zh-cn/web/api/readablestream/tee/index.md @@ -16,7 +16,7 @@ slug: Web/API/ReadableStream/tee ## 语法 ```js -tee() +tee(); ``` ### 参数 @@ -61,8 +61,9 @@ function fetchStream(stream, list) { // value for fetch streams is a Uint8Array charsReceived += value.length; const chunk = value; - let listItem = document.createElement('li'); - listItem.textContent = 'Read ' + charsReceived + ' characters so far. Current chunk = ' + chunk; + let listItem = document.createElement("li"); + listItem.textContent = + "Read " + charsReceived + " characters so far. Current chunk = " + chunk; list.appendChild(listItem); // Read some more, and call this function again diff --git a/files/zh-cn/web/api/readablestreamdefaultcontroller/close/index.md b/files/zh-cn/web/api/readablestreamdefaultcontroller/close/index.md index 9b82577cf3be56..2500c1c48c3469 100644 --- a/files/zh-cn/web/api/readablestreamdefaultcontroller/close/index.md +++ b/files/zh-cn/web/api/readablestreamdefaultcontroller/close/index.md @@ -12,7 +12,7 @@ reader 将仍然可以从流中读取任何先前入队的数据块,但是一 ## 语法 ```js -close() +close(); ``` ### 参数 @@ -42,15 +42,15 @@ const stream = new ReadableStream({ // 将随机字符串添加到流 controller.enqueue(string); // 在屏幕上展示 - let listItem = document.createElement('li'); + let listItem = document.createElement("li"); listItem.textContent = string; list1.appendChild(listItem); }, 1000); - button.addEventListener('click', function() { + button.addEventListener("click", function () { clearInterval(interval); fetchStream(); controller.close(); - }) + }); }, pull(controller) { // 在这个例子中不使用 pull @@ -59,7 +59,7 @@ const stream = new ReadableStream({ // 如果取消了 reader,则会调用该函数, // 所以我们应该在这里停止生成字符串 clearInterval(interval); - } + }, }); ``` diff --git a/files/zh-cn/web/api/readablestreamdefaultcontroller/enqueue/index.md b/files/zh-cn/web/api/readablestreamdefaultcontroller/enqueue/index.md index 38fc31b5e51701..2da0aa7fca1e4c 100644 --- a/files/zh-cn/web/api/readablestreamdefaultcontroller/enqueue/index.md +++ b/files/zh-cn/web/api/readablestreamdefaultcontroller/enqueue/index.md @@ -10,7 +10,7 @@ slug: Web/API/ReadableStreamDefaultController/enqueue ## 语法 ```js -enqueue(chunk) +enqueue(chunk); ``` ### 参数 @@ -41,15 +41,15 @@ const stream = new ReadableStream({ // 将随机字符串添加到流 controller.enqueue(string); // 在屏幕上展示 - let listItem = document.createElement('li'); + let listItem = document.createElement("li"); listItem.textContent = string; list1.appendChild(listItem); }, 1000); - button.addEventListener('click', function() { + button.addEventListener("click", function () { clearInterval(interval); fetchStream(); controller.close(); - }) + }); }, pull(controller) { // 在这个例子中不使用 pull @@ -58,7 +58,7 @@ const stream = new ReadableStream({ // 如果取消了 reader,则会调用该函数, // 所以我们应该在这里停止生成字符串 clearInterval(interval); - } + }, }); ``` diff --git a/files/zh-cn/web/api/readablestreamdefaultcontroller/error/index.md b/files/zh-cn/web/api/readablestreamdefaultcontroller/error/index.md index d781d2523abbc4..b3d3e67b2841a6 100644 --- a/files/zh-cn/web/api/readablestreamdefaultcontroller/error/index.md +++ b/files/zh-cn/web/api/readablestreamdefaultcontroller/error/index.md @@ -12,7 +12,7 @@ slug: Web/API/ReadableStreamDefaultController/error ## 语法 ```js -error(e) +error(e); ``` ### 参数 diff --git a/files/zh-cn/web/api/readablestreamdefaultcontroller/index.md b/files/zh-cn/web/api/readablestreamdefaultcontroller/index.md index 16e3ef73a90192..ae843dc05974a3 100644 --- a/files/zh-cn/web/api/readablestreamdefaultcontroller/index.md +++ b/files/zh-cn/web/api/readablestreamdefaultcontroller/index.md @@ -41,15 +41,15 @@ const stream = new ReadableStream({ // 将随机字符串添加到流 controller.enqueue(string); // 在屏幕上展示 - let listItem = document.createElement('li'); + let listItem = document.createElement("li"); listItem.textContent = string; list1.appendChild(listItem); }, 1000); - button.addEventListener('click', function() { + button.addEventListener("click", function () { clearInterval(interval); fetchStream(); controller.close(); - }) + }); }, pull(controller) { // 在这个例子中不使用 pull @@ -58,7 +58,7 @@ const stream = new ReadableStream({ // 如果取消了 reader,则会调用该函数, // 所以我们应该在这里停止生成字符串 clearInterval(interval); - } + }, }); ``` diff --git a/files/zh-cn/web/api/readablestreamdefaultreader/cancel/index.md b/files/zh-cn/web/api/readablestreamdefaultreader/cancel/index.md index 67e12d8d58d0cb..f17d56ce132049 100644 --- a/files/zh-cn/web/api/readablestreamdefaultreader/cancel/index.md +++ b/files/zh-cn/web/api/readablestreamdefaultreader/cancel/index.md @@ -14,8 +14,8 @@ cancel 用于在不再需要来自一个流的任何数据的情况下完全结 ## 语法 ```js -cancel() -cancel(reason) +cancel(); +cancel(reason); ``` ### 参数 @@ -53,8 +53,12 @@ function fetchStream() { // 从流中获取的数据是一个 Uint8Array charsReceived += value.length; const chunk = value; - let listItem = document.createElement('li'); - listItem.textContent = 'Received ' + charsReceived + ' characters so far. Current chunk = ' + chunk; + let listItem = document.createElement("li"); + listItem.textContent = + "Received " + + charsReceived + + " characters so far. Current chunk = " + + chunk; list2.appendChild(listItem); result += chunk; // 再次调用该函数以读取更多数据 diff --git a/files/zh-cn/web/api/readablestreamdefaultreader/closed/index.md b/files/zh-cn/web/api/readablestreamdefaultreader/closed/index.md index 11ca87dedb5b90..ac53da4c2d24e0 100644 --- a/files/zh-cn/web/api/readablestreamdefaultreader/closed/index.md +++ b/files/zh-cn/web/api/readablestreamdefaultreader/closed/index.md @@ -17,8 +17,8 @@ slug: Web/API/ReadableStreamDefaultReader/closed ```js reader.closed.then(() => { - console.log('reader closed'); -}) + console.log("reader closed"); +}); ``` ## 规范 diff --git a/files/zh-cn/web/api/readablestreamdefaultreader/read/index.md b/files/zh-cn/web/api/readablestreamdefaultreader/read/index.md index d988cf5f2eccef..8a4a83351ba2a0 100644 --- a/files/zh-cn/web/api/readablestreamdefaultreader/read/index.md +++ b/files/zh-cn/web/api/readablestreamdefaultreader/read/index.md @@ -10,7 +10,7 @@ slug: Web/API/ReadableStreamDefaultReader/read ## 语法 ```js -read() +read(); ``` ### 参数 @@ -55,8 +55,12 @@ function fetchStream() { // 从流中获取的数据是一个 Uint8Array charsReceived += value.length; const chunk = value; - let listItem = document.createElement('li'); - listItem.textContent = 'Received ' + charsReceived + ' characters so far. Current chunk = ' + chunk; + let listItem = document.createElement("li"); + listItem.textContent = + "Received " + + charsReceived + + " characters so far. Current chunk = " + + chunk; list2.appendChild(listItem); result += chunk; // 再次调用该函数以读取更多数据 @@ -74,8 +78,8 @@ async function* makeTextFileLineIterator(fileURL) { const utf8Decoder = new TextDecoder("utf-8"); let response = await fetch(fileURL); let reader = response.body.getReader(); - let {value: chunk, done: readerDone} = await reader.read(); - chunk = chunk ? utf8Decoder.decode(chunk, {stream: true}) : ""; + let { value: chunk, done: readerDone } = await reader.read(); + chunk = chunk ? utf8Decoder.decode(chunk, { stream: true }) : ""; let re = /\r\n|\n|\r/gm; let startIndex = 0; for (;;) { @@ -85,8 +89,9 @@ async function* makeTextFileLineIterator(fileURL) { break; } let remainder = chunk.substr(startIndex); - ({value: chunk, done: readerDone} = await reader.read()); - chunk = remainder + (chunk ? utf8Decoder.decode(chunk, {stream: true}) : ""); + ({ value: chunk, done: readerDone } = await reader.read()); + chunk = + remainder + (chunk ? utf8Decoder.decode(chunk, { stream: true }) : ""); startIndex = re.lastIndex = 0; continue; } diff --git a/files/zh-cn/web/api/readablestreamdefaultreader/readablestreamdefaultreader/index.md b/files/zh-cn/web/api/readablestreamdefaultreader/readablestreamdefaultreader/index.md index 9388d2ba229703..2f5dd3899f3fed 100644 --- a/files/zh-cn/web/api/readablestreamdefaultreader/readablestreamdefaultreader/index.md +++ b/files/zh-cn/web/api/readablestreamdefaultreader/readablestreamdefaultreader/index.md @@ -12,7 +12,7 @@ slug: Web/API/ReadableStreamDefaultReader/ReadableStreamDefaultReader ## 语法 ```js -new ReadableStreamDefaultReader(stream) +new ReadableStreamDefaultReader(stream); ``` ### 参数 @@ -50,8 +50,12 @@ function fetchStream() { // 从流中获取的数据是一个 Uint8Array charsReceived += value.length; const chunk = value; - let listItem = document.createElement('li'); - listItem.textContent = 'Received ' + charsReceived + ' characters so far. Current chunk = ' + chunk; + let listItem = document.createElement("li"); + listItem.textContent = + "Received " + + charsReceived + + " characters so far. Current chunk = " + + chunk; list2.appendChild(listItem); result += chunk; // 再次调用该函数以读取更多数据 diff --git a/files/zh-cn/web/api/readablestreamdefaultreader/releaselock/index.md b/files/zh-cn/web/api/readablestreamdefaultreader/releaselock/index.md index 5f5d579837fea9..52e689f0db1e26 100644 --- a/files/zh-cn/web/api/readablestreamdefaultreader/releaselock/index.md +++ b/files/zh-cn/web/api/readablestreamdefaultreader/releaselock/index.md @@ -14,7 +14,7 @@ reader 的锁在仍有待处理的读取请求时无法释放,即,如果 rea ## 语法 ```js -releaseLock() +releaseLock(); ``` ### 参数 diff --git a/files/zh-cn/web/api/request/arraybuffer/index.md b/files/zh-cn/web/api/request/arraybuffer/index.md index c6bed0a5a1e6ca..011fc9cc7f618a 100644 --- a/files/zh-cn/web/api/request/arraybuffer/index.md +++ b/files/zh-cn/web/api/request/arraybuffer/index.md @@ -10,7 +10,7 @@ slug: Web/API/Request/arrayBuffer ## 语法 ```js -arrayBuffer() +arrayBuffer(); ``` ### 参数 @@ -26,12 +26,12 @@ arrayBuffer() ```js const myArray = new Uint8Array(10); -const request = new Request('/myEndpoint', { - method: 'POST', - body: myArray +const request = new Request("/myEndpoint", { + method: "POST", + body: myArray, }); -request.arrayBuffer().then(function(buffer) { +request.arrayBuffer().then(function (buffer) { // do something with the buffer sent in the request }); ``` diff --git a/files/zh-cn/web/api/request/blob/index.md b/files/zh-cn/web/api/request/blob/index.md index f04e31b26a961e..fbde08eda65573 100644 --- a/files/zh-cn/web/api/request/blob/index.md +++ b/files/zh-cn/web/api/request/blob/index.md @@ -10,7 +10,7 @@ slug: Web/API/Request/blob ## 语法 ```js -blob() +blob(); ``` ### 参数 @@ -24,15 +24,17 @@ blob() ## 示例 ```js -const obj = {hello: 'world'}; -const myBlob = new Blob([JSON.stringify(obj, null, 2)], {type : 'application/json'}); +const obj = { hello: "world" }; +const myBlob = new Blob([JSON.stringify(obj, null, 2)], { + type: "application/json", +}); -const request = new Request('/myEndpoint', { - method: 'POST', - body: myBlob - }); +const request = new Request("/myEndpoint", { + method: "POST", + body: myBlob, +}); -request.blob().then(function(myBlob) { +request.blob().then(function (myBlob) { // do something with the blob sent in the request }); ``` diff --git a/files/zh-cn/web/api/request/bodyused/index.md b/files/zh-cn/web/api/request/bodyused/index.md index f02e738163c95b..8eecd20d4829bd 100644 --- a/files/zh-cn/web/api/request/bodyused/index.md +++ b/files/zh-cn/web/api/request/bodyused/index.md @@ -14,14 +14,14 @@ slug: Web/API/Request/bodyUsed ## 示例 ```js -const request = new Request('/myEndpoint', { - method: 'POST', - body: 'Hello world' +const request = new Request("/myEndpoint", { + method: "POST", + body: "Hello world", }); request.bodyUsed; // false -request.text().then(function(bodyAsText) { +request.text().then(function (bodyAsText) { console.log(request.bodyUsed); // true }); ``` diff --git a/files/zh-cn/web/api/request/cache/index.md b/files/zh-cn/web/api/request/cache/index.md index 22d180e98d9164..f3fa34c6117eb7 100644 --- a/files/zh-cn/web/api/request/cache/index.md +++ b/files/zh-cn/web/api/request/cache/index.md @@ -47,26 +47,30 @@ A `RequestCache` value. The available values are: ```js // Download a resource with cache busting, to bypass the cache // completely. -fetch("some.json", {cache: "no-store"}) - .then(function(response) { /* consume the response */ }); +fetch("some.json", { cache: "no-store" }).then(function (response) { + /* consume the response */ +}); // Download a resource with cache busting, but update the HTTP // cache with the downloaded resource. -fetch("some.json", {cache: "reload"}) - .then(function(response) { /* consume the response */ }); +fetch("some.json", { cache: "reload" }).then(function (response) { + /* consume the response */ +}); // Download a resource with cache busting when dealing with a // properly configured server that will send the correct ETag // and Date headers and properly handle If-Modified-Since and // If-None-Match request headers, therefore we can rely on the // validation to guarantee a fresh response. -fetch("some.json", {cache: "no-cache"}) - .then(function(response) { /* consume the response */ }); +fetch("some.json", { cache: "no-cache" }).then(function (response) { + /* consume the response */ +}); // Download a resource with economics in mind! Prefer a cached // albeit stale response to conserve as much bandwidth as possible. -fetch("some.json", {cache: "force-cache"}) - .then(function(response) { /* consume the response */ }); +fetch("some.json", { cache: "force-cache" }).then(function (response) { + /* consume the response */ +}); ``` ## Specifications diff --git a/files/zh-cn/web/api/request/clone/index.md b/files/zh-cn/web/api/request/clone/index.md index 1d555c6a0686b6..cdbfd2d8692eac 100644 --- a/files/zh-cn/web/api/request/clone/index.md +++ b/files/zh-cn/web/api/request/clone/index.md @@ -28,7 +28,7 @@ var newRequest = request.clone(); 在下面的代码中,我们使用 {{domxref("Request.Request()")}} 构造函数创建了一个新的 request 对象 (请求当前文件夹中的一个图片文件),然后拷贝了这个 `request` 对象。 ```js -var myRequest = new Request('flowers.jpg'); +var myRequest = new Request("flowers.jpg"); var newRequest = myRequest.clone(); // a copy of the request is now stored in newRequest ``` diff --git a/files/zh-cn/web/api/request/credentials/index.md b/files/zh-cn/web/api/request/credentials/index.md index 355b465c02ef90..7672a2b6ee9f00 100644 --- a/files/zh-cn/web/api/request/credentials/index.md +++ b/files/zh-cn/web/api/request/credentials/index.md @@ -26,7 +26,7 @@ A {{domxref("RequestCredentials")}} value. 在以下代码中,我们使用{{domxref("Request.Request()")}}创建了一个新的 request(为了一个与脚本在同一目录下的图片文件),接着将 request credentials 存入一个变量: ```js -var myRequest = new Request('flowers.jpg'); +var myRequest = new Request("flowers.jpg"); var myCred = myRequest.credentials; // returns "same-origin" by default ``` diff --git a/files/zh-cn/web/api/request/formdata/index.md b/files/zh-cn/web/api/request/formdata/index.md index bee605902ab19a..7e46e35cec3933 100644 --- a/files/zh-cn/web/api/request/formdata/index.md +++ b/files/zh-cn/web/api/request/formdata/index.md @@ -10,7 +10,7 @@ slug: Web/API/Request/formData ## 语法 ```js -formData() +formData(); ``` ### 参数 @@ -27,15 +27,15 @@ formData() const formData = new FormData(); const fileField = document.querySelector('input[type="file"]'); -formData.append('username', 'abc123'); -formData.append('avatar', fileField.files[0]); +formData.append("username", "abc123"); +formData.append("avatar", fileField.files[0]); -const request = new Request('/myEndpoint', { - method: 'POST', - body: formData +const request = new Request("/myEndpoint", { + method: "POST", + body: formData, }); -request.formData().then(function(data) { +request.formData().then(function (data) { // do something with the formdata sent in the request }); ``` diff --git a/files/zh-cn/web/api/request/headers/index.md b/files/zh-cn/web/api/request/headers/index.md index fa96788e895315..f3082ffc7609f5 100644 --- a/files/zh-cn/web/api/request/headers/index.md +++ b/files/zh-cn/web/api/request/headers/index.md @@ -22,7 +22,7 @@ var myHeaders = request.headers; 在下面的代码段中,我们使用 {{domxref("Request.Request()")}} 构造函数(为获取与脚本处于同一目录的图片文件)创建新请求,然后将请求 headers 保存到变量中: ```js -var myRequest = new Request('flowers.jpg'); +var myRequest = new Request("flowers.jpg"); var myHeaders = myRequest.headers; // Headers {} ``` @@ -30,16 +30,18 @@ var myHeaders = myRequest.headers; // Headers {} ```js var myHeaders = new Headers(); -myHeaders.append('Content-Type', 'image/jpeg'); +myHeaders.append("Content-Type", "image/jpeg"); -var myInit = { method: 'GET', - headers: myHeaders, - mode: 'cors', - cache: 'default' }; +var myInit = { + method: "GET", + headers: myHeaders, + mode: "cors", + cache: "default", +}; -var myRequest = new Request('flowers.jpg',myInit); +var myRequest = new Request("flowers.jpg", myInit); -myContentType = myRequest.headers.get('Content-Type'); // returns 'image/jpeg' +myContentType = myRequest.headers.get("Content-Type"); // returns 'image/jpeg' ``` ## 规范 diff --git a/files/zh-cn/web/api/request/json/index.md b/files/zh-cn/web/api/request/json/index.md index 928f0de8b96aea..8cd7f576203761 100644 --- a/files/zh-cn/web/api/request/json/index.md +++ b/files/zh-cn/web/api/request/json/index.md @@ -12,7 +12,7 @@ slug: Web/API/Request/json ## 语法 ```js -json() +json(); ``` ### 参数 @@ -26,14 +26,14 @@ json() ## 示例 ```js -const obj = {hello: 'world'}; +const obj = { hello: "world" }; -const request = new Request('/myEndpoint', { - method: 'POST', - body: JSON.stringify(obj) - }); +const request = new Request("/myEndpoint", { + method: "POST", + body: JSON.stringify(obj), +}); -request.json().then(function(data) { +request.json().then(function (data) { // do something with the data sent in the request }); ``` diff --git a/files/zh-cn/web/api/request/method/index.md b/files/zh-cn/web/api/request/method/index.md index ba7859e0aff879..9b19da2f831087 100644 --- a/files/zh-cn/web/api/request/method/index.md +++ b/files/zh-cn/web/api/request/method/index.md @@ -22,7 +22,7 @@ A {{domxref("ByteString")}} indicating the method of the request. In the following snippet, we create a new request using the {{domxref("Request.Request()")}} constructor (for an image file in the same directory as the script), then save the method of the request in a variable: ```js -var myRequest = new Request('flowers.jpg'); +var myRequest = new Request("flowers.jpg"); var myMethod = myRequest.method; // GET ``` diff --git a/files/zh-cn/web/api/request/mode/index.md b/files/zh-cn/web/api/request/mode/index.md index 3a36a3ba3a3570..5c8c59e555c11f 100644 --- a/files/zh-cn/web/api/request/mode/index.md +++ b/files/zh-cn/web/api/request/mode/index.md @@ -37,7 +37,7 @@ var myMode = request.mode; In the following snippet, we create a new request using theconstructor (for an image file in the same directory as the script), then save the request mode in a variable: ```js -var myRequest = new Request('flowers.jpg'); +var myRequest = new Request("flowers.jpg"); var myMode = myRequest.mode; // returns "cors" by default ``` diff --git a/files/zh-cn/web/api/request/request/index.md b/files/zh-cn/web/api/request/request/index.md index 8b0484ab0d6580..f86024ea9aa39f 100644 --- a/files/zh-cn/web/api/request/request/index.md +++ b/files/zh-cn/web/api/request/request/index.md @@ -50,16 +50,18 @@ var myRequest = new Request(input[, init]); 在我们的获取请求示例 [Fetch Request example](https://github.com/mdn/fetch-examples/tree/gh-pages/fetch-request) (see [Fetch Request live](http://mdn.github.io/fetch-examples/fetch-request/)) 中,我们使用构造函数创建一个新的`Request`对象,然后使用 {{domxref("GlobalFetch.fetch")}} 发送请求。由于我们正在获取图像,我们在响应上运行 {{domxref("Body.blob")}} 以为其提供正确的 MIME 类型,以便对其进行正确处理,然后为其创建一个 Object URL,并将其显示在 {{htmlelement("img")}} 元素中。 ```js -var myImage = document.querySelector('img'); - -var myRequest = new Request('flowers.jpg'); - -fetch(myRequest).then(function(response) { - return response.blob(); -}).then(function(response) { - var objectURL = URL.createObjectURL(response); - myImage.src = objectURL; -}); +var myImage = document.querySelector("img"); + +var myRequest = new Request("flowers.jpg"); + +fetch(myRequest) + .then(function (response) { + return response.blob(); + }) + .then(function (response) { + var objectURL = URL.createObjectURL(response); + myImage.src = objectURL; + }); ``` 在[Fetch Request with init example](https://github.com/mdn/fetch-examples/tree/gh-pages/fetch-request-with-init) (参见 [Fetch Request init live](http://mdn.github.io/fetch-examples/fetch-request-with-init/)) 我们做了同样的事情,只不过我们在调用`fetch() 时,还`传递进了一个 init 对象: @@ -93,14 +95,16 @@ fetch(myRequest,myInit).then(function(response) { 也可以使用在 init 中使用对象字面量作为 `headers`。 ```js -var myInit = { method: 'GET', - headers: { - 'Content-Type': 'image/jpeg' - }, - mode: 'cors', - cache: 'default' }; - -var myRequest = new Request('flowers.jpg', myInit); +var myInit = { + method: "GET", + headers: { + "Content-Type": "image/jpeg", + }, + mode: "cors", + cache: "default", +}; + +var myRequest = new Request("flowers.jpg", myInit); ``` 也可以把 {{domxref("Request")}} 对象再作参数传递进 `Request()` 构造器来创建一个请求的副本(就像调用{{domxref("Request.clone","clone()")}}一样)。 diff --git a/files/zh-cn/web/api/request/text/index.md b/files/zh-cn/web/api/request/text/index.md index 51cd7a60fb0a5f..33727cfde938c2 100644 --- a/files/zh-cn/web/api/request/text/index.md +++ b/files/zh-cn/web/api/request/text/index.md @@ -10,7 +10,7 @@ slug: Web/API/Request/text ## 语法 ```js -text() +text(); ``` ### 参数 @@ -26,12 +26,12 @@ text() ```js const text = "Hello world"; -const request = new Request('/myEndpoint', { - method: 'POST', - body: text +const request = new Request("/myEndpoint", { + method: "POST", + body: text, }); -request.text().then(function(text) { +request.text().then(function (text) { // do something with the text sent in the request }); ``` diff --git a/files/zh-cn/web/api/request/url/index.md b/files/zh-cn/web/api/request/url/index.md index 2658b5c1fab5e8..1097ef5df65913 100644 --- a/files/zh-cn/web/api/request/url/index.md +++ b/files/zh-cn/web/api/request/url/index.md @@ -22,7 +22,7 @@ A {{domxref("USVString")}} indicating the url of the request. In the following snippet, we create a new request using the {{domxref("Request.Request()")}} constructor (for an image file in the same directory as the script), then save the url of the request in a variable: ```js -var myRequest = new Request('flowers.jpg'); +var myRequest = new Request("flowers.jpg"); var myURL = myRequest.url; // "http://mdn.github.io/fetch-examples/fetch-request/flowers.jpg" ``` diff --git a/files/zh-cn/web/api/resize_observer_api/index.md b/files/zh-cn/web/api/resize_observer_api/index.md index 6ac93e1a31bc25..2d63cc65499d0f 100644 --- a/files/zh-cn/web/api/resize_observer_api/index.md +++ b/files/zh-cn/web/api/resize_observer_api/index.md @@ -46,12 +46,12 @@ const resizeObserver = new ResizeObserver((entries) => { if (entry.borderBoxSize) { entry.target.style.borderRadius = calcBorderRadius( entry.borderBoxSize[0].inlineSize, - entry.borderBoxSize[0].blockSize + entry.borderBoxSize[0].blockSize, ); } else { entry.target.style.borderRadius = calcBorderRadius( entry.contentRect.width, - entry.contentRect.height + entry.contentRect.height, ); } } diff --git a/files/zh-cn/web/api/resizeobserver/disconnect/index.md b/files/zh-cn/web/api/resizeobserver/disconnect/index.md index 96b906dd3c15c0..5975ebba0c9348 100644 --- a/files/zh-cn/web/api/resizeobserver/disconnect/index.md +++ b/files/zh-cn/web/api/resizeobserver/disconnect/index.md @@ -28,9 +28,9 @@ disconnect() ## 示例 ```js -btn.addEventListener('click', () => { +btn.addEventListener("click", () => { resizeObserver.disconnect(); -}) +}); ``` ## 规范 diff --git a/files/zh-cn/web/api/resizeobserver/index.md b/files/zh-cn/web/api/resizeobserver/index.md index b219b1f1ae95b7..cf1c1592c41fec 100644 --- a/files/zh-cn/web/api/resizeobserver/index.md +++ b/files/zh-cn/web/api/resizeobserver/index.md @@ -38,38 +38,49 @@ slug: Web/API/ResizeObserver JavaScript 看起来像这样: ```js -const h1Elem = document.querySelector('h1'); -const pElem = document.querySelector('p'); -const divElem = document.querySelector('body > div'); +const h1Elem = document.querySelector("h1"); +const pElem = document.querySelector("p"); +const divElem = document.querySelector("body > div"); const slider = document.querySelector('input[type="range"]'); const checkbox = document.querySelector('input[type="checkbox"]'); -divElem.style.width = '600px'; +divElem.style.width = "600px"; -slider.addEventListener('input', () => { +slider.addEventListener("input", () => { divElem.style.width = `${slider.value}px`; -}) +}); const resizeObserver = new ResizeObserver((entries) => { for (const entry of entries) { if (entry.contentBoxSize) { // Firefox implements `contentBoxSize` as a single content rect, rather than an array - const contentBoxSize = Array.isArray(entry.contentBoxSize) ? entry.contentBoxSize[0] : entry.contentBoxSize; - - h1Elem.style.fontSize = `${Math.max(1.5, contentBoxSize.inlineSize / 200)}rem`; - pElem.style.fontSize = `${Math.max(1, contentBoxSize.inlineSize / 600)}rem`; + const contentBoxSize = Array.isArray(entry.contentBoxSize) + ? entry.contentBoxSize[0] + : entry.contentBoxSize; + + h1Elem.style.fontSize = `${Math.max( + 1.5, + contentBoxSize.inlineSize / 200, + )}rem`; + pElem.style.fontSize = `${Math.max( + 1, + contentBoxSize.inlineSize / 600, + )}rem`; } else { - h1Elem.style.fontSize = `${Math.max(1.5, entry.contentRect.width / 200)}rem`; + h1Elem.style.fontSize = `${Math.max( + 1.5, + entry.contentRect.width / 200, + )}rem`; pElem.style.fontSize = `${Math.max(1, entry.contentRect.width / 600)}rem`; } } - console.log('Size changed'); + console.log("Size changed"); }); resizeObserver.observe(divElem); -checkbox.addEventListener('change', () => { +checkbox.addEventListener("change", () => { if (checkbox.checked) { resizeObserver.observe(divElem); } else { diff --git a/files/zh-cn/web/api/resizeobserver/observe/index.md b/files/zh-cn/web/api/resizeobserver/observe/index.md index 30dd99c786d924..d4efb2b2aed10a 100644 --- a/files/zh-cn/web/api/resizeobserver/observe/index.md +++ b/files/zh-cn/web/api/resizeobserver/observe/index.md @@ -51,18 +51,33 @@ const resizeObserver = new ResizeObserver((entries) => { if (entry.contentBoxSize) { // Checking for chrome as using a non-standard array if (entry.contentBoxSize[0]) { - h1Elem.style.fontSize = `${Math.max(1.5, entry.contentBoxSize[0].inlineSize / 200)}rem`; - pElem.style.fontSize = `${Math.max(1, entry.contentBoxSize[0].inlineSize / 600)}rem`; + h1Elem.style.fontSize = `${Math.max( + 1.5, + entry.contentBoxSize[0].inlineSize / 200, + )}rem`; + pElem.style.fontSize = `${Math.max( + 1, + entry.contentBoxSize[0].inlineSize / 600, + )}rem`; } else { - h1Elem.style.fontSize = `${Math.max(1.5, entry.contentBoxSize.inlineSize / 200)}rem`; - pElem.style.fontSize = `${Math.max(1, entry.contentBoxSize.inlineSize / 600)}rem`; + h1Elem.style.fontSize = `${Math.max( + 1.5, + entry.contentBoxSize.inlineSize / 200, + )}rem`; + pElem.style.fontSize = `${Math.max( + 1, + entry.contentBoxSize.inlineSize / 600, + )}rem`; } } else { - h1Elem.style.fontSize = `${Math.max(1.5, entry.contentRect.width / 200)}rem`; + h1Elem.style.fontSize = `${Math.max( + 1.5, + entry.contentRect.width / 200, + )}rem`; pElem.style.fontSize = `${Math.max(1, entry.contentRect.width / 600)}rem`; } } - console.log('Size changed'); + console.log("Size changed"); }); resizeObserver.observe(divElem); @@ -71,7 +86,7 @@ resizeObserver.observe(divElem); 带有一个可选的对象的 `observe()` 看起来像这样: ```js -resizeObserver.observe(divElem, { box : 'border-box' }); +resizeObserver.observe(divElem, { box: "border-box" }); ``` ## 规范 From ed18266297d92df857b86b524266a9424d835ad0 Mon Sep 17 00:00:00 2001 From: Allo Date: Sat, 29 Jul 2023 21:13:20 +0800 Subject: [PATCH 2/3] add `-nolint` suffix to syntax code block --- .../offlineaudiocontext/offlineaudiocontext/index.md | 12 +++++++----- .../web/api/performanceobserver/disconnect/index.md | 4 ++-- .../web/api/progressevent/progressevent/index.md | 6 +++--- files/zh-cn/web/api/readablestream/cancel/index.md | 6 +++--- .../zh-cn/web/api/readablestream/getreader/index.md | 6 +++--- .../web/api/readablestream/pipethrough/index.md | 6 +++--- files/zh-cn/web/api/readablestream/pipeto/index.md | 6 +++--- files/zh-cn/web/api/readablestream/tee/index.md | 4 ++-- .../readablestreamdefaultcontroller/close/index.md | 4 ++-- .../readablestreamdefaultcontroller/enqueue/index.md | 4 ++-- .../readablestreamdefaultcontroller/error/index.md | 4 ++-- .../api/readablestreamdefaultreader/read/index.md | 4 ++-- .../readablestreamdefaultreader/index.md | 4 ++-- .../readablestreamdefaultreader/releaselock/index.md | 4 ++-- files/zh-cn/web/api/request/arraybuffer/index.md | 4 ++-- files/zh-cn/web/api/request/blob/index.md | 4 ++-- files/zh-cn/web/api/request/formdata/index.md | 4 ++-- files/zh-cn/web/api/request/json/index.md | 4 ++-- files/zh-cn/web/api/request/text/index.md | 4 ++-- 19 files changed, 48 insertions(+), 46 deletions(-) diff --git a/files/zh-cn/web/api/offlineaudiocontext/offlineaudiocontext/index.md b/files/zh-cn/web/api/offlineaudiocontext/offlineaudiocontext/index.md index de224cb8760a86..9b1ba9e63ccf76 100644 --- a/files/zh-cn/web/api/offlineaudiocontext/offlineaudiocontext/index.md +++ b/files/zh-cn/web/api/offlineaudiocontext/offlineaudiocontext/index.md @@ -9,17 +9,19 @@ slug: Web/API/OfflineAudioContext/OfflineAudioContext ## 语法 -```js -var myOfflineAudio = new OfflineAudioContext(numOfChannels, length, sampleRate); +```js-nolint +new OfflineAudioContext(options) + +new OfflineAudioContext(numberOfChannels, length, sampleRate) ``` ### 参数 -- numOfChannels +- `numberOfChannels` - : An integer 代表该缓冲区拥有的声道的数目。该实现需要支持至少 32 个声道。 -- length +- `length` - : 代表采样帧缓冲区的大小的整数。 -- sampleRate +- `sampleRate` - : 采样帧每一秒的线性音频数据的采样率。该实现必须支持在 22050 到 96000 之间的采样率,44100 是最经常用到的采样率。 这里有个重要的警告,你可以通过不带参数的使用 `new AudioContext()` 构造函数创建一个新的 {{domxref("AudioContext")}},但是 `OfflineAudioContext()` 构造函数必须带上三个参数。当你通过 {{domxref("AudioContext.createBuffer")}} 方法创建一个新的{{domxref("AudioBuffer")}} 时,你也是需要做一样的事情。想要知道更多信息,请阅读我们的基本概念指南的 [音频片段:帧,样本和声道](/zh-CN/docs/Web/API/Web_Audio_API/Basic_concepts_behind_Web_Audio_API#音频片段:帧,样本和声道)。 diff --git a/files/zh-cn/web/api/performanceobserver/disconnect/index.md b/files/zh-cn/web/api/performanceobserver/disconnect/index.md index dd0484381b48d8..c315e132c01279 100644 --- a/files/zh-cn/web/api/performanceobserver/disconnect/index.md +++ b/files/zh-cn/web/api/performanceobserver/disconnect/index.md @@ -9,8 +9,8 @@ slug: Web/API/PerformanceObserver/disconnect ## 语法 -```js -disconnect(); +```js-nolint +disconnect() ``` ### 参数 diff --git a/files/zh-cn/web/api/progressevent/progressevent/index.md b/files/zh-cn/web/api/progressevent/progressevent/index.md index 72dea6118f9fe9..f811ea56f87255 100644 --- a/files/zh-cn/web/api/progressevent/progressevent/index.md +++ b/files/zh-cn/web/api/progressevent/progressevent/index.md @@ -9,9 +9,9 @@ slug: Web/API/ProgressEvent/ProgressEvent ## 语法 -```js -new ProgressEvent(type); -new ProgressEvent(type, options); +```js-nolint +new ProgressEvent(type) +new ProgressEvent(type, options) ``` ### 参数 diff --git a/files/zh-cn/web/api/readablestream/cancel/index.md b/files/zh-cn/web/api/readablestream/cancel/index.md index 30ab0ea16b8d2a..28fd62e3b97775 100644 --- a/files/zh-cn/web/api/readablestream/cancel/index.md +++ b/files/zh-cn/web/api/readablestream/cancel/index.md @@ -11,9 +11,9 @@ cancel 用于在不再需要来自它的任何数据的情况下(即使仍有 ## 语法 -```js -cancel(); -cancel(reason); +```js-nolint +cancel() +cancel(reason) ``` ### 参数 diff --git a/files/zh-cn/web/api/readablestream/getreader/index.md b/files/zh-cn/web/api/readablestream/getreader/index.md index f37dd936974d70..ac2ad827b380ec 100644 --- a/files/zh-cn/web/api/readablestream/getreader/index.md +++ b/files/zh-cn/web/api/readablestream/getreader/index.md @@ -9,9 +9,9 @@ slug: Web/API/ReadableStream/getReader ## 语法 -```js -getReader(); -getReader(mode); +```js-nolint +getReader() +getReader(mode) ``` ### 参数 diff --git a/files/zh-cn/web/api/readablestream/pipethrough/index.md b/files/zh-cn/web/api/readablestream/pipethrough/index.md index 08f2c704575b29..601a0a6f7e8a8a 100644 --- a/files/zh-cn/web/api/readablestream/pipethrough/index.md +++ b/files/zh-cn/web/api/readablestream/pipethrough/index.md @@ -11,9 +11,9 @@ slug: Web/API/ReadableStream/pipeThrough ## 语法 -```js -pipeThrough(transformStream); -pipeThrough(transformStream, options); +```js-nolint +pipeThrough(transformStream) +pipeThrough(transformStream, options) ``` ### 参数 diff --git a/files/zh-cn/web/api/readablestream/pipeto/index.md b/files/zh-cn/web/api/readablestream/pipeto/index.md index 0695c235b6fa19..d10455c3e3b733 100644 --- a/files/zh-cn/web/api/readablestream/pipeto/index.md +++ b/files/zh-cn/web/api/readablestream/pipeto/index.md @@ -11,9 +11,9 @@ slug: Web/API/ReadableStream/pipeTo ## 语法 -```js -pipeTo(destination); -pipeTo(destination, options); +```js-nolint +pipeTo(destination) +pipeTo(destination, options) ``` ### 参数 diff --git a/files/zh-cn/web/api/readablestream/tee/index.md b/files/zh-cn/web/api/readablestream/tee/index.md index 2d91e5020e250c..69f38d4d79bb54 100644 --- a/files/zh-cn/web/api/readablestream/tee/index.md +++ b/files/zh-cn/web/api/readablestream/tee/index.md @@ -15,8 +15,8 @@ slug: Web/API/ReadableStream/tee ## 语法 -```js -tee(); +```js-nolint +tee() ``` ### 参数 diff --git a/files/zh-cn/web/api/readablestreamdefaultcontroller/close/index.md b/files/zh-cn/web/api/readablestreamdefaultcontroller/close/index.md index 2500c1c48c3469..3b85281f619f62 100644 --- a/files/zh-cn/web/api/readablestreamdefaultcontroller/close/index.md +++ b/files/zh-cn/web/api/readablestreamdefaultcontroller/close/index.md @@ -11,8 +11,8 @@ reader 将仍然可以从流中读取任何先前入队的数据块,但是一 ## 语法 -```js -close(); +```js-nolint +close() ``` ### 参数 diff --git a/files/zh-cn/web/api/readablestreamdefaultcontroller/enqueue/index.md b/files/zh-cn/web/api/readablestreamdefaultcontroller/enqueue/index.md index 2da0aa7fca1e4c..72605453a95bab 100644 --- a/files/zh-cn/web/api/readablestreamdefaultcontroller/enqueue/index.md +++ b/files/zh-cn/web/api/readablestreamdefaultcontroller/enqueue/index.md @@ -9,8 +9,8 @@ slug: Web/API/ReadableStreamDefaultController/enqueue ## 语法 -```js -enqueue(chunk); +```js-nolint +enqueue(chunk) ``` ### 参数 diff --git a/files/zh-cn/web/api/readablestreamdefaultcontroller/error/index.md b/files/zh-cn/web/api/readablestreamdefaultcontroller/error/index.md index b3d3e67b2841a6..63e26dd6abc35f 100644 --- a/files/zh-cn/web/api/readablestreamdefaultcontroller/error/index.md +++ b/files/zh-cn/web/api/readablestreamdefaultcontroller/error/index.md @@ -11,8 +11,8 @@ slug: Web/API/ReadableStreamDefaultController/error ## 语法 -```js -error(e); +```js-nolint +error(e) ``` ### 参数 diff --git a/files/zh-cn/web/api/readablestreamdefaultreader/read/index.md b/files/zh-cn/web/api/readablestreamdefaultreader/read/index.md index 8a4a83351ba2a0..de7ed6b7fd855a 100644 --- a/files/zh-cn/web/api/readablestreamdefaultreader/read/index.md +++ b/files/zh-cn/web/api/readablestreamdefaultreader/read/index.md @@ -9,8 +9,8 @@ slug: Web/API/ReadableStreamDefaultReader/read ## 语法 -```js -read(); +```js-nolint +read() ``` ### 参数 diff --git a/files/zh-cn/web/api/readablestreamdefaultreader/readablestreamdefaultreader/index.md b/files/zh-cn/web/api/readablestreamdefaultreader/readablestreamdefaultreader/index.md index 2f5dd3899f3fed..8539f999c798f9 100644 --- a/files/zh-cn/web/api/readablestreamdefaultreader/readablestreamdefaultreader/index.md +++ b/files/zh-cn/web/api/readablestreamdefaultreader/readablestreamdefaultreader/index.md @@ -11,8 +11,8 @@ slug: Web/API/ReadableStreamDefaultReader/ReadableStreamDefaultReader ## 语法 -```js -new ReadableStreamDefaultReader(stream); +```js-nolint +new ReadableStreamDefaultReader(stream) ``` ### 参数 diff --git a/files/zh-cn/web/api/readablestreamdefaultreader/releaselock/index.md b/files/zh-cn/web/api/readablestreamdefaultreader/releaselock/index.md index 52e689f0db1e26..55249978d94008 100644 --- a/files/zh-cn/web/api/readablestreamdefaultreader/releaselock/index.md +++ b/files/zh-cn/web/api/readablestreamdefaultreader/releaselock/index.md @@ -13,8 +13,8 @@ reader 的锁在仍有待处理的读取请求时无法释放,即,如果 rea ## 语法 -```js -releaseLock(); +```js-nolint +releaseLock() ``` ### 参数 diff --git a/files/zh-cn/web/api/request/arraybuffer/index.md b/files/zh-cn/web/api/request/arraybuffer/index.md index 011fc9cc7f618a..60681f12733e40 100644 --- a/files/zh-cn/web/api/request/arraybuffer/index.md +++ b/files/zh-cn/web/api/request/arraybuffer/index.md @@ -9,8 +9,8 @@ slug: Web/API/Request/arrayBuffer ## 语法 -```js -arrayBuffer(); +```js-nolint +arrayBuffer() ``` ### 参数 diff --git a/files/zh-cn/web/api/request/blob/index.md b/files/zh-cn/web/api/request/blob/index.md index fbde08eda65573..d2295e677b45e1 100644 --- a/files/zh-cn/web/api/request/blob/index.md +++ b/files/zh-cn/web/api/request/blob/index.md @@ -9,8 +9,8 @@ slug: Web/API/Request/blob ## 语法 -```js -blob(); +```js-nolint +blob() ``` ### 参数 diff --git a/files/zh-cn/web/api/request/formdata/index.md b/files/zh-cn/web/api/request/formdata/index.md index 7e46e35cec3933..cc5608862f48cd 100644 --- a/files/zh-cn/web/api/request/formdata/index.md +++ b/files/zh-cn/web/api/request/formdata/index.md @@ -9,8 +9,8 @@ slug: Web/API/Request/formData ## 语法 -```js -formData(); +```js-nolint +formData() ``` ### 参数 diff --git a/files/zh-cn/web/api/request/json/index.md b/files/zh-cn/web/api/request/json/index.md index 8cd7f576203761..4a4f95ee5b3a4a 100644 --- a/files/zh-cn/web/api/request/json/index.md +++ b/files/zh-cn/web/api/request/json/index.md @@ -11,8 +11,8 @@ slug: Web/API/Request/json ## 语法 -```js -json(); +```js-nolint +json() ``` ### 参数 diff --git a/files/zh-cn/web/api/request/text/index.md b/files/zh-cn/web/api/request/text/index.md index 33727cfde938c2..562b3b5febabf5 100644 --- a/files/zh-cn/web/api/request/text/index.md +++ b/files/zh-cn/web/api/request/text/index.md @@ -9,8 +9,8 @@ slug: Web/API/Request/text ## 语法 -```js -text(); +```js-nolint +text() ``` ### 参数 From 433ffb0b057cf53c0a05730fbbae495b77193eb4 Mon Sep 17 00:00:00 2001 From: A1lo Date: Sat, 29 Jul 2023 21:15:01 +0800 Subject: [PATCH 3/3] Update index.md --- .../web/api/readablestreamdefaultreader/cancel/index.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/files/zh-cn/web/api/readablestreamdefaultreader/cancel/index.md b/files/zh-cn/web/api/readablestreamdefaultreader/cancel/index.md index f17d56ce132049..6438900961b55b 100644 --- a/files/zh-cn/web/api/readablestreamdefaultreader/cancel/index.md +++ b/files/zh-cn/web/api/readablestreamdefaultreader/cancel/index.md @@ -13,9 +13,9 @@ cancel 用于在不再需要来自一个流的任何数据的情况下完全结 ## 语法 -```js -cancel(); -cancel(reason); +```js-nolint +cancel() +cancel(reason) ``` ### 参数