From 706e69870e0ed9330a56ea586cd9545529a69f4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=AB=E8=B0=B7=E5=89=91=E4=BB=99?= Date: Fri, 8 Sep 2023 18:48:52 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E6=8A=80=E8=83=BD=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=E5=87=BA=E6=9D=A5=E5=BE=88=E5=A4=9Anull=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script-universal_function.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/script-universal_function.js b/script-universal_function.js index 6c5624b4..340a55d2 100644 --- a/script-universal_function.js +++ b/script-universal_function.js @@ -284,7 +284,7 @@ DocumentFragment.prototype.ap = function(...args) { arg.forEach(item=>this.ap(item)); } - else //其他内容的转换为文字添加 + else if (arg !== null && arg !== void 0) //其他内容的转换为文字添加 { this.append(arg); } @@ -298,8 +298,9 @@ Array.prototype.nodeJoin = function(separator) const frg = document.createDocumentFragment(); this.forEach((item, idx, arr)=>{ frg.ap(item); - if (idx < (arr.length - 1) && separator !== undefined) + if (idx < (arr.length - 1) && separator !== null && separator !== void 0) { frg.ap(separator instanceof Node ? separator.cloneNode(true) : separator); + } }); return frg; } @@ -339,7 +340,7 @@ function tp(stringsArr, ...keys) { fragment.append(stringsArr[i]); const key = keys[i]; const value = Number.isInteger(key) ? values[key] : dict[key]; - if (value !== undefined) { + if (value !== null && value !== void 0) { try { fragment.append((value instanceof Node && keys.lastIndexOf(key) !== i) ? value.cloneNode(true) : value); //如果是不最后一个匹配的标签,就插入克隆的DOM,否则可以插入原始的DOM(保留行为) }