普通页面标签中的这个片段在<head>
我使用它的任何浏览器中都会崩溃:
function insert(str, position, insert) {
var current = str;
var start = current.slice(0, position);
var end = current.slice(position, current.length);
return start + insert + end;
};
var str = "1000";
var nbd = str.length;
var mod = nbd%3;
for (var i = mod; i < str.length; i+3) {
str = insert(str,i,",");
}
console.log(str);
console.log("mod: " + mod);
此外,如果该函数insert
是字符串的原型,那么它也会崩溃:
String.prototype.insert(position, insert) {
var current = this;
var start = current.slice(0, position);
var end = current.slice(position, current.length);
return start + insert + end;
}