xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

js repeatify & no for loop

js repeatify

https://www.sitepoint.com/5-typical-javascript-interview-exercises/

padStart

String.prototype.repeatify = String.prototype.repeatify || function (times = 1) {
  console.log(this)
  // String {"abx"}
  return [...``.padStart(times, ` `)].map((item, i) => item = this).join(``);
};

`abx`.repeatify(3);
// "abxabxabx"

arrow function bug


// ES6 无法改变 this 的指向

String.prototype.repeatify = (times = 1, that = this) => [...``.padStart(times, ` `)].map((item, i) => item = that).join(``);

`abx`.repeatify(3);
// "[object Window][object Window][object Window]"

Uint8Array

TypedArray bug


refs



©xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!


原文地址:https://www.cnblogs.com/xgqfrms/p/13034475.html