You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
function objectFactory() {
var obj = new Object(),
Constructor = [].shift.call(arguments);
obj.__proto__ = Constructor.prototype;
var ret = Constructor.apply(obj, arguments);
return typeof ret === 'object' ? ret : obj;
};
Function.prototype.bind2 = function (context) {
if (typeof this !== "function") {
throw new Error("Function.prototype.bind - what is trying to be bound is not callable");
}
var self = this;
var args = Array.prototype.slice.call(arguments, 1);
var fNOP = function () {};
var fBound = function () {
var bindArgs = Array.prototype.slice.call(arguments);
return self.apply(this instanceof fNOP ? this : context, args.concat(bindArgs));
}
fNOP.prototype = this.prototype;
fBound.prototype = new fNOP();
return fBound;
}
JavaScript深入之new的模拟实现
new操作符做了这些事:
它创建了一个全新的对象
它会被执行[[Prototype]](也就是__proto__)链接
它使this指向新创建的对象
通过new创建的每个对象将最终被[[Prototype]]链接到这个函数的prototype对象上
如果函数没有返回对象类型Object(包含Functoin, Array, Date, RegExg, Error),那么new表达式中的函数调用将返回该对象引用
参考: mqyqingfeng/Blog#13
JavaScript深入之call和apply的模拟实现
参考:mqyqingfeng/Blog#11
JavaScript深入之bind的模拟实现
一句话介绍 bind:
参考: mqyqingfeng/Blog#12
防抖 & 节流
参考:mqyqingfeng/Blog#22
mqyqingfeng/Blog#26
深浅拷贝
浅拷贝:
深拷贝
参考: mqyqingfeng/Blog#32
手写Promise
参考: https://juejin.im/post/6844904094079926286#heading-0
手写数组去重、扁平化函数
数组去重
方式一:Set(ES6)
方式二:reduce
方法三:filter
The text was updated successfully, but these errors were encountered: