随笔分类 - 方法重现
摘要:/* call: 1:调用函数 2:改变函数的this指向为call的第一个参数 3:返回函数的返回值 */ Function.prototype.myCall = function (context, ...argv) { /* context有3种形态 - null undefined > wi
阅读全文
摘要:// 封装一个函数,拷贝传入的数据 function deepClone(data) { if ((typeof data != "object" && typeof data != "function") || data null) { // 把基本数据类型过滤出来 return data; }
阅读全文
摘要:let str='a-b-c'; String.prototype.Up=function(){ //将要替换的字符串赋值给str; let str=this; for(var i=0;i<str.length;i++){ //检测'-'出现的下标 let index=str.indexOf('-'
阅读全文
摘要:let arr=[1,2,3,4,5]; //在数组显示原型上定义自定义方法 Array.prototype.newMap=function(func){ //定义新数组用来接收回调函数返回值 let arr=[]; //for循环遍历数组 for(let i=0;i<this.length;i++
阅读全文
摘要:new 关键字法 let a=1,b=2,c=3; function fn(a,b,c){ } function new1(fn,...str){ //1.创建一个空的简单JavaScript对象(即`{}`) let obj={}; //2.为步骤1新创建的对象添加属性`__proto__`,将该
阅读全文
摘要:let arr=[1,2,4,5,3]; Array.prototype.NewSort=function(func){ var flag; for(var i=0;i<this.length-1;i++){ for(var j=1;j<this.length-i;j++){ flag=func(t
阅读全文