Javascript ReferenceError: range is not defined Error



代码不工作,编译器提示"ReferenceError: range is not defined">

代码复制自这本著名的书:https://eloquentjavascript.net/05_higher_order.html#c_EiK2Y8M/Mh代码:

function repeat(n, action) {
for (let i = 0; i < n; i++) {
console.log(action(...range(0, i)));
}
}
repeat(5, Math.max);

I try let range = new range ();但它不工作

尝试0…n-1,尝试Array(n).keys()

function repeat(n, action) {
for (let i = 0; i < n; i++) {
console.log(action(...Array(i).keys()));
}
}
repeat(5, Math.max);

JSRange功能用于文本

const paragraphs = document.querySelectorAll("p");
const range = new Range();
range.setStartBefore(paragraphs[1]);
range.setEndAfter(paragraphs[2]);
const selection = window.getSelection();
selection.addRange(range);
<p>One</p>
<p>Two - this will get selected</p>
<p>Three - this will get selected</p>
<p>Four</p>

相关内容

  • 没有找到相关文章