随笔分类 - JavaScript
关于 JavaScript 的知识点
摘要:/* quick: 实现快速排序 @params ary [array] 需要排序的数组 @return [array] 排序后的新数组 */ function quick(ary) { // 4、结束递归(当 ary 中小于等于一项,则不用处理) if (ary.length <= 1) { re
阅读全文
摘要:/* insert: 实现插入排序 @params ary [array] 需要排序的数组 @return [array] 排序后的新数组 */ function insert(ary) { // 1、准备一个新数组,先保存一个数据 let temp = []; temp.push(ary[0]);
阅读全文
摘要:/* 冒泡排序的思想: 让数组中的当前项和后一项进行比较, 如果当前项比后一项大,则两项交换位置(让大的靠后)即可 */ /* bubble: 实现冒泡排序 @params ary [array] 需要排序的数组 @return [array] 排序后的新数组 */ function bubble(
阅读全文
摘要:/* Array.prototype.push = function A(val) { this[this.length] = val; // =>this.length 在原来的基础上加1 return this.length; } */ let obj = { 2: 3, 3: 4, lengt
阅读全文
摘要:/* * == 进行比较的时候,如果左右两边数据类型不一样,则先转换为相同的数据类型,然后在进行比较 * 1、{} == {} false 两个数据进行比较,比较的是堆内存的地址 * 2、null == undefined true | null undefined false * 3、NaN ==
阅读全文
摘要:/* * 1、本应匿名的函数如果设置了函数名,在外面还是无法调用,但是在函数里面是可以使用的 * 2、而且类似于创建常量一样。这个名字存储的值不能再被修改 */ var b = 10; (function b() { b = 20; console.log(b) })(); console.log(
阅读全文
摘要:// 定时器是异步编程:每一轮循环设置定时器,无需等定时器触发执行,继续下一轮循环(定时器触发的时候,循环已经结束了) for (var i = 0; i < 10; i++) { setTimeout(() => { console.log(i); }, 1000); } // => let 存在
阅读全文
摘要:一:合并后的数组为:['A1','A2','A',B1','B2','B','C1','C2','C','D1','D2','D'] let ary1 = ['A1', 'A2', 'B1', 'B2', 'C1', 'C2', 'D1', 'D2']; let ary2 = ['
阅读全文
摘要:/* 基于内置的 new 关键词,我们可以创建 Dog 的一个实例 zhangsan ,实例可以调用原型上的属性和方法 需求:自己实现一个 _new 方法,也可以模拟出内置 new 后的结果 */ /* let zhangsan = new Dog('张三'); 1、像普通函数执行一样,形成一个私有
阅读全文
摘要:let arr = [[21, 2, 17, 18, 2], [3, 4, 95, 5, 5], [6, 6, 7, 8], [9, 10, [11, 12]]]; // =>【1、扁平化】 使用 ES6 中提供的 Array.prototype.flat 处理 // arr = arr.flat(
阅读全文
摘要:let str = "no作no死,你能你can,不能no哔哔!", reg = /\b[a-z]+\b/ig; str = str.replace(reg, value => { return " " + value + " "; }).trim(); // => String.prototype
阅读全文
摘要:<body> <div class="box clearfix"></div> <div name="zs"></div> <div class="box"></div> <div name="ls"></div> <div class="attr"></div> <div class="box2"
阅读全文
摘要:/* 1、(?=pattern) => 正向预查:要求做匹配的时候,必须满足 pattern 这个条件 2、(?!pattern) => 负向预查:要求做匹配的时候,必须不满足 pattern 这个条件 3、注意:括号里面的内容只是条件,并不参与真正的捕获。 */ 一: 一个6~16位的字符串,必须
阅读全文
摘要:<!DOCTYPE html> <html> <head> <title>图片的懒加载</title> <style> * { margin: 0; padding: 0; } .container { margin:0 auto; width: 800px; } .imgBox { height:
阅读全文
摘要:function classA() { classA.a = function () { console.log(1) } this.a = function () { console.log(2) } } classA.prototype.a = function () { console.log
阅读全文
摘要:let str = "https://www.baidu.com/index.php?tn=78040160_5_pg&ch=12#video" let reg = /^(?:(http|https|ftp):\/\/)?((?:[\w-]+\.)+[a-z0-9]+)((?:\/[^/?#]*)+
阅读全文
摘要:// example 1 var a = {}, b = '123', c = 123; a[b] = 'b'; a[c] = 'c'; console.log(a[b]); // =>c 因为:a["123"] <=> a[123] // example 2 var a = {}, b = Sym
阅读全文
摘要:/** 1、循环原始字符串的每一项,让每一项从当前位置向后截取 H.length 个字符, 然后和 Y 进行比较,如果不一样,继续循环;如果一样返回当前索引即可 **/ function myIndexOf(Y) { let lenY = Y.length, lenH = H.length, res
阅读全文
摘要:let str = "hyt加油!!FIGHTING" str = str.replace(/[a-zA-Z]/g, content => { // => content:每次正则匹配的结果 // => 1、验证是否为大写字母:把字母转换为大写字母后判断是否和之前一样,如果一样,之前就是大写的; /
阅读全文
摘要:把一个函数B作为实参传递给另一个函数 A ,函数 A 在执行的时候,可以把传递进来的函数 B 去执行(执行 N 次,可以传值,可以改 this) function each(arr, callBack){ // =>callBack:function(item,index){} for(let i
阅读全文

浙公网安备 33010602011771号