var escapeMap={ "<" : "<", ">" : ">", '"' : """, "'" : "'", "&" : "&" }; var str="<html>" var str2=str.replace(/[><]/g, ($0, $1) => escapeMap[$0] ); console.log(str2);//<html>
[quote=引用 1 楼 jslang 的回复:] 这是 箭头函数 , 是es6新增语法 https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Functions/Arrow_functions ($0, $1) => escapeMap[$0] 等于 function ($0, $1) { return escapeMap[$0]; }
这是 箭头函数 , 是es6新增语法 https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Functions/Arrow_functions ($0, $1) => escapeMap[$0] 等于 function ($0, $1) { return escapeMap[$0]; }
87,997
社区成员
224,709
社区内容
加载中
试试用AI创作助手写篇文章吧