跳至主要內容

String.cooked

小于 1 分钟featurees-proposal

String.cookedopen in new window

模块

esnext.string.cookedopen in new window

类型

interface StringConstructor {
  cooked(template: Array<string>, ...substitutions: Array<string>): string;
}

入口点

core-js/proposals/string-cooked
core-js(-pure)/full/string/cooked

示例

示例open in new window:

function safePath(strings, ...subs) {
  return String.cooked(strings, ...subs.map((sub) => encodeURIComponent(sub)));
}

let id = "spottie?";

safePath`/cats/${id}`; // => /cats/spottie%3F