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
Array.prototype.mybind=function(thisArg, ...argsArr){if(typeofthis!=="function"){throwError("no function");}if(thisArg===undefined||thisArg===null){thisArg=window;}else{thisArg=Object(thisArg);}letfunc=this;returnfunction(...args){returnfunc.apply(thisinstanceoffunc ? this : thisArg,args);};};functionfoo(...args){returnargs;}constbar=foo.mybind(null,[1,2]);bar(1,2);
debounce
functiondebounce(func,wait){lettimer=null;returnfunction(){clearTimeout(timer);timer=setTimeout(()=>func(),wait);};}functiondebounce2(func,wait,immediate){lettimer=null;returnfunction(){clearTimeout(timer);if(immediate){letcallNow=!timer;timer=setTimeout(()=>func(),wait);if(callNow){func();}}else{timer=setTimeout(()=>func(),wait);}};}functionfoo(...args){console.log(1);returnargs;}constbar=debounce(foo,3000);constbar1=debounce2(foo,3000,true);for(leti=0;i<30000;i++){// bar()bar1();}// for (let i = 0; i < 30000000; i++) {// bar()// }
functionmynew(F, ...args){letobj={};Object.setPrototypeOf(obj,F.prototype);constres=F.apply(obj,args);constisObject=typeofres==="object"&&typeofres!=="null";constisFunction=typeofres==="function";returnisObject||isFunction ? res : obj;}functionFoo(...args){this.args=args;}constres=mynew(Foo,1,2,3);console.log(res);
instanceof
functionmyinstanceof(left,right){if((typeofleft!=="object"&&typeofleft!=="function")||typeofleft===null){returnfalse;}letproto=Object.getPrototypeOf(left);while(true){if(proto===null){returnfalse;}if(proto===right.prototype){returntrue;}proto=Object.getPrototypeOf(proto);}}functionfoo(){}// const bar = new foo()// console.log(Object.getPrototypeOf(bar) === foo.prototype)// const res = myinstanceof(bar, foo)constres=myinstanceof(foo,Function);console.log(res);
functionis(x,y){// 0 === -0 falseif(x===y){returnx!==0||y!==0||1/x===1/y;}else{// NaN === NaN truereturnx!==x&&y!==y;}}console.log(is(0,-0));console.log(is(NaN,NaN));
Array.prototype.filter()
Array.prototype.map()
Array.prototype.forEach()
Array.prototype.every()
Array.prototype.some()
Array.prototype.reduce()
Array.prototype.join
Array.prototype.flat
Array.prototype.splice
Array.prototype.apply
Array.prototype.call
Array.prototype.bind
debounce
throttle
new
instanceof
Object.is
Object.assign
Promise
https://www.shanejix.com/posts/Promises%20implementation%20with%20ES6%20class/
tagName
The text was updated successfully, but these errors were encountered: