es6字符串的扩展底层实现____startsWith
程序员文章站
2023-12-21 18:25:46
...
代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>repeat</title>
<script>
String.prototype.repeat2=function (size) {
let buffer ='';
for(let i=0;i<size;i++){
buffer =buffer+this;
}
return buffer;
}
let data='hello';
let buffer=data.repeat2(2);
console.log(buffer);
</script>
</head>
<body>
</body>
</html>
结果: