js repeatify & no for loop

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



&copyxgqfrms 2012-2020

www.cnblogs.com 發佈文章使用:只允許註冊用戶纔可以訪問!


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章