WD Blog

我干了什么 究竟拿了时间换了什么

js小白模拟系列_模拟数组 fill,find,findIndex

"Hello World, Hello Blog"

fill 1 2 3 4 5 Array.prototype.myFill = function (value,start = 0,end = this.length) { for(let i = start; i < end; i++) { this[i] = value; ...

js小白模拟系列_模拟数组 concat,slice,join

"Hello World, Hello Blog"

concat 版本1.0 只能接收一个参数 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Array.prototype.concat = function (arr) { var self = this; var newArr = []; var len1 = self.length;...

js小白模拟系列_模拟Object.create()

"Hello World, Hello Blog"

版本1.0 用new模拟 1 2 3 4 5 Object.myCreate = function (obj) { function F () {}; F.prototype = obj; return new F(); } 版本2.0 1 2 3 4 5 Object.myCreate = function (obj) { va...

js小白模拟系列_模拟new

"Hello World, Hello Blog"

版本1.0 1 2 3 4 5 6 7 function myNew (fn) { var self = Object.create(fn.prototype); return function () { fn.apply(self,arguments); return self } } 版本2.0 1 2 3 4 ...

js小白模拟系列_模拟call,apply

"Hello World, Hello Blog"

call 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Function.prototype.myCall = function (context) { var context = context || window; context.fn = this;// 这就完成this指向的改变了. var arr = []; ...

js小白模拟系列_模拟bind

"Hello World, Hello Blog"

这个比call和apply 要稍微复杂点,多层函数的嵌套 版本1.0 没解决原型链 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 Function.prototype.myBind = function (context) { var context = context || window; var args = []...

js小白_找出100以内的所有质数,渡一课程回顾

"Hello World, Hello Blog"

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 function prime (n) { var n = parseInt(n) || 100; var arr = []; var obj = {}; for(var i = 1;i <= n;i++){ ...