我用过这个:
String.Prototype.left = function left(count){
return this.substr(0,count);
}
并以这种方式应用:
var string = "Hello Stack!";
console.log(string.left(5));
控制台告诉我:
TypeError: example.left is not a function
console.log(example.left(5));
我该如何解决?问题在哪里?
答案 0 :(得分:0)
String.prototype.left = function(index){
return this.substring(0,index);
}
var str = "Hello World";
console.log(str.left(5));