es6字符串的扩展底层实现____startsWith

代码:

<!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>

结果:

猜你喜欢

转载自blog.csdn.net/qq_34607371/article/details/81208427