随笔分类 - JS
摘要://787. K 站中转内最便宜的航班 var findCheapestPrice = function (n, flights, src, dst, K) { //把出和入存到map //key为dst,value为[src, cost] const innerMap = new Map(); /
阅读全文
摘要:1 class TreeNode { 2 constructor(key) { 3 this.key = key; 4 this.leftChild = null; 5 this.rightChild = null; 6 this.parent = null; 7 } 8 rightRotate()
阅读全文
摘要:变量声明是一门编程语言的重要组成部分 ,每门编程语言都有其声明变量的形式,今天来简单了解一下JS的变量声明方式。 与C语言的区别 在C语言中,如果我们需要使用一个变量,必须在使用前声明它,否则程序就会报错,同时我们也必须指定变量的类型,如int,float,char等等,因此根据这种特性,C语言也被
阅读全文
摘要:class LazyMan { constructor(name){ this.nama = name; this.queue = []; this.queue.push(() => { console.log("Hi! This is " + name + "!"); this.next(); }
阅读全文
摘要:对于一个函数: function add(a,b,c){ return a + b + c } 我们希望实现一个效果,我们希望有另外一个函数curryingAdd,使得curryingAdd(1,2,3),curryingAdd(1,2)(3),curryingAdd(1)(2,3)和add(1,2
阅读全文
摘要:聊聊什么是jsonp 说到son大家应该是很熟悉的,jsonp和json只差了一个字母,那么他们是不是他们有着非常密切的关系呢?答案是确定的。jsonp全称”JSON with Padding“,意思应该是”填充的json“。那么问题就来了,填充指的是什么,怎么填充呢? 聊聊script标签 <sc
阅读全文
摘要:关于new的原理可参考:https://www.cnblogs.com/guanghe/p/11356347.html 下面是实现代码: function New(fn){ //fn是父类 var res = {}; if(fn.prototype !== null) { res.__proto__
阅读全文
摘要:关于instanceof的具体用法和原理,可参考:https://blog.csdn.net/LL18781132750/article/details/81115081 下面给出instanceof的实现代码: function myInstanceof(left,right){ var prot
阅读全文
摘要:现有一个父类: function People(name){ //属性 this.name = name //实例方法 this.sleep=function(){ console.log(this.name + '正在睡觉') } } //原型方法 People.prototype.eat = f
阅读全文
摘要:class EventEmitter { constructor(){ this.messageBox = {} } on(eventName,fn){ const callbacks = this.messageBox[eventName] || [] callbacks.push(fn) thi
阅读全文
摘要:call: Function.prototype.$call = function(context) { var context = context || window; context.fn = this; var args = Array.from(arguments).slice(1) con
阅读全文
摘要:Array.prototype.fakeFilter = function fakeFilter(fn, context) { if (typeof fn !== "function") { throw new TypeError(`${fn} is not a function`); } let
阅读全文
摘要:乱序 方法一:用sort生成随机序列 function mixArr(arr){ return arr.sort(() => { return Math.random() - 0.5; }) } 关于sort方法的参数请参考:https://www.xp.cn/b.php/95773.html 但这
阅读全文
摘要:防抖 概念:老实说,第一次听到这个词的时候觉得真的太生动了,我想大家从字面上就能get到他的意思。比如说点击出鼠标的时候不小心手抖了,一下子快速点了两次,但如果函数本身只需要触发一次,这样就导致了不确定的结果,所以,防抖的作用是限制函数在一定时间内只能触发一次,防止你”手抖“。当然这个手抖可能是无意
阅读全文
摘要:对象浅拷贝有不少实现方法,下面就来学习一下Object.assign。 基本用法 1 const one = {a: 1, b: 2} 2 const two = {c: '3', d: '4'} 3 var three = Object.assign({e: 5}, one, two) 4 con
阅读全文
摘要:let let不存在变量提升 老规矩,先看代码 1 console.log(a) //undefined 2 let lock = false 3 4 if (lock) { 5 var a = 10 6 }else{ 7 var a =20 8 } 9 10 console.log(a) //20
阅读全文
摘要:变量提升 变量提升应该是var最引人瞩目的一个特点了。不说废话,先上代码。 1 //code1: 2 a = 10 3 var a 4 console.log(a)//10 5 6 //code2: 7 var a 8 a = 10 9 console.log(a)//10 聪明的你肯定都猜对了输出
阅读全文

浙公网安备 33010602011771号