1
在以下代碼中,編譯器(在'compile'時間)沒有提出關於groups.shift()
的投訴,但抱怨depths.shift()
不是函數。我對什麼是盲目的? (我試過重新命名depths
,重新輸入等)爲什麼shift()在一個數組上不起作用,除非另一個在其他數組上工作
const tag1x = (elem, content, groups = ['?','?','?'], depths = ['?','?'], optional = true, level = 0) => {
let option = optional ? '?' : '';
let template = `
${'\t'.repeat(level)}(${groups.shift()}:<$1[^>]*?DDD(${depths.shift()}:[0-9]+)[^>]*>)$3
${'\t'.repeat(level)}(${groups.shift()}:$2)
${'\t'.repeat(level)}(${groups.shift()}:</$1[^>]*?DDD(${depths.shift()}:[0-9]+)[^>]*>)$3
`;
return form(template, elem, content, option);
}
但是,如果我用shift
一般能正常工作的所有罪狀:以上
const tag1x = (elem, content, groups = ['?','?','?'], depths = ['?','?'], optional = true, level = 0) => {
let option = optional ? '?' : '';
let template = `
${'\t'.repeat(level)}(${groups.shift()}:<$1[^>]*?DDD(${[].shift.call(depths)}:[0-9]+)[^>]*>)$3
${'\t'.repeat(level)}(${groups.shift()}:$2)
${'\t'.repeat(level)}(${groups.shift()}:</$1[^>]*?DDD(${[].shift.call(depths)}:[0-9]+)[^>]*>)$3
`;
return form(template, elem, content, option);
}
是功能齊全。