我想将一个数字数组传递给String.fromCharCode()方法,我读取了另一个thread,并试图在fromCharCode之后进行链式应用,但是它对我不起作用。下面是代码:
function rot13(str) {
var reStr = "";
var asciiCodedArr = [70,82,69,69,32,67,79,68,69,32,67,65,77,80];
reStr = String.fromCharCode().apply(null, asciiCodedArr);
return reStr;
}
rot13("SERR PBQR PNZC");它对我大喊大叫:
TypeError: String.fromCharCode(...).apply is not a function我在哪里搞砸了?
发布于 2017-03-07 03:11:11
删除()后的fromCharCode,您将是黄金。
本质上,您试图在调用apply (它是一个字符串,因此没有来自Function.prototype的方法)的结果上找到一个fromCharCode方法,而不是在函数fromCharCode本身上。
function rot13(str) {
var reStr = "";
var asciiCodedArr = [70, 82, 69, 69, 32, 67, 79, 68, 69, 32, 67, 65, 77, 80];
reStr = String.fromCharCode.apply(null, asciiCodedArr);
return reStr;
}
console.log(rot13("SERR PBQR PNZC"));
发布于 2017-03-07 03:11:19
删除()
reStr = String.fromCharCode.apply(null, asciiCodedArr);不
reStr = String.fromCharCode().apply(null, asciiCodedArr);https://stackoverflow.com/questions/42639456
复制相似问题