要学习自己造点轮子啊
透明的前端
这个作者很懒,什么都没留下…
展开
-
new 操作符的模拟实现
function objectFactory(){ let obj = {}; let constructor = Array.prototype.shift.call(arguments); obj.__proto__=constructor.prototype; let result = constructor.apply(obj,arguments); return typeof result === 'object'?result:obj; }原创 2021-05-10 15:37:10 · 199 阅读 · 0 评论 -
实现instanceof方法
function instanceof_myself(leftValue,rightValue) { let rightPrototype = rightValue.prototype; //获取右侧构造函数对应的原型 let leftProto=leftValue.__proto__;//获取左侧实例对应的原型 while(true) { if (leftProto === null) { return false; } el原创 2021-04-28 18:00:12 · 312 阅读 · 0 评论 -
call、apply和bind
call call()方法在使用一个指定的this值和若干个指定的参数值的前提下调用某个函数或方法 Function.prototype.call=function(context) { context=context || Window; context.fn=this; let args=[]; for(let i=1;i<arguments.length;i++) { args.push("arguments["+i+"]"); } let result = eval('cont原创 2021-05-08 15:45:30 · 98 阅读 · 0 评论