随笔分类 -  JavaScript

js知识
摘要:输入: nums='100,300,50,30,500,103,605,720' k=3 输出:[ 300, 300, 500, 500, 605, 720 ] 大概就是 [100,300,50]找最大值是300;[300,50,30]最大值300,[50,30,500]最大值是500.。。。。 让 阅读全文
posted @ 2021-04-10 09:36 JMH0113 阅读(299) 评论(0) 推荐(0)
摘要:class MyPromise { constructor(executor) { this.state = 'pending'; this.value = null; try { executor(this.resolve.bind(this),this.reject.bind(this)); } 阅读全文
posted @ 2021-04-04 10:14 JMH0113 阅读(139) 评论(0) 推荐(0)
摘要:class MyPromise { constructor(executor) { this.state = 'pending'; //初始状态为pending this.value = null; try { // class中默认是严格模式,这个executor是MyPromise中的函数,他的 阅读全文
posted @ 2021-04-03 19:50 JMH0113 阅读(63) 评论(0) 推荐(0)
摘要:输入:head = [1,2,3,4] 输出:[2,1,4,3]遍历思路:先定义一个节点0,让0->head,让1指向next的next,也就是3,因为目的是给1和2做交换,让0指向2,2指向1,这样就完成1和2的交换了,然后让temp跳过2指向1,继续迭代,最后返回0的next // 遍历方式 v 阅读全文
posted @ 2021-03-21 10:33 JMH0113 阅读(44) 评论(0) 推荐(0)
摘要:运用sort方法和取随机数可以实现 let arr = [1,2,3,4,5,6,7,8]; arr.sort(function(a,b){ let ran=Math.random(); if(ran>0.5) { return a-b; }else{ return b-a; } }) consol 阅读全文
posted @ 2021-03-17 10:30 JMH0113 阅读(134) 评论(0) 推荐(0)
摘要:因为JavaScript是静态作用域,作用域在对象创建的时候就已经确定了,但JavaScript又是一门面向对象语言,面向对象的基本特点封装继承多态,为了满足这种面向对象的特点所以引入了this,this的指向是动态的,不在函数对象定义时绑定,this指向当前调用他的对象。 阅读全文
posted @ 2021-03-13 18:41 JMH0113 阅读(68) 评论(0) 推荐(0)