问题2: 创建 “原生(native)” 方法
在 String 对象上定义一个 repeatify 函数。这个函数接受一个整数参数,来明确字符串需要重复几次。这个函数要求字符串重复指定的次数。举个例子:
`console.log('hello'.repeatify(3));``应该打印出 hellohellohello .
答案
一种可能的实现如下所示:
String.prototype.repeatify = String.prototype.repeatify || function(times) { var str = ''; for (var i = 0; i < times; i++) { str += this; } return str;};这个问题测试了开发人员对于javascript中继承的掌握,以及

