上一页 1 2 3 4 5 6 7 8 ··· 13 下一页
摘要: 冒泡 function bubbleSort(arr) { var len = arr.length for (var i = 0; i < len; i++) { for (var j = 0; j < len - 1 - i; j++) { if (arr[j] > arr[j + 1]) { 阅读全文
posted @ 2021-02-26 18:49 懒懒同学不懒 阅读(46) 评论(0) 推荐(0)
摘要: 数组乱序 实现一个数组乱序,每一个元素出现在每一个位置的概率是平均的 function noSort(arr) { const len = arr.length for (let i = 0; i < len; i++) { const random = Math.random() * (len - 阅读全文
posted @ 2021-02-23 11:02 懒懒同学不懒 阅读(197) 评论(0) 推荐(0)
摘要: for语句 支持中断,支持异步 let str = ''; for (let i = 0; i < 9; i++) { str = str + i; } console.log(str); //'012345678' 中断示例 var i = 0; for (var i = 0; ; i++) { 阅读全文
posted @ 2021-02-22 14:11 懒懒同学不懒 阅读(96) 评论(0) 推荐(0)
摘要: 1、在严格模式中一部分字符变成了保留的关键字。这些字符包括implements, interface, let, package, private, protected, public, static和yield。在严格模式下,不能再用这些名字作为变量名或者形参名。 2、禁止使用with语句 3、创 阅读全文
posted @ 2021-02-21 22:10 懒懒同学不懒 阅读(270) 评论(0) 推荐(0)
摘要: 宏任务:setTimeout/setImmediate 微任务:Promise 浏览器: 执行一个宏任务,执行所有微任务 node:先执行所有宏任务,再执行微任务 function test() { console.log('start') setTimeout(() => { console.lo 阅读全文
posted @ 2021-02-20 14:32 懒懒同学不懒 阅读(73) 评论(0) 推荐(0)
摘要: function objectFactory(...args) { //创建实例对象 let obj = {} //构造函数取第一个参数 let constructor = args.shift() //实例对象的__proto__属性与构造函数的prototype相同 obj.__proto__ 阅读全文
posted @ 2021-02-19 14:31 懒懒同学不懒 阅读(52) 评论(0) 推荐(0)
摘要: ES6引入rest参数,形式为...变量名,用于获取函数多余参数。 语法: function foo(a, b, ...args) { // ... } rest参数只能作为最后一个参数,否则会报错 function foo(a, b, ...args, c) { console.log(args) 阅读全文
posted @ 2021-02-18 10:50 懒懒同学不懒 阅读(67) 评论(0) 推荐(0)
摘要: 防抖(debounce) 在事件被触发n秒后再执行回调,如果在这n秒内又被触发,则重新计时 function debounce(func, delay) { let timer = null return function (...args) { if (timer) { clearTimeout( 阅读全文
posted @ 2021-02-17 18:50 懒懒同学不懒 阅读(77) 评论(0) 推荐(0)
摘要: 三者的对比 call、apply与bind都是用来改变this指向的。 call与apply返回结果为函数调用结果,bind返回结果为新的函数,还需要重新调用 let obj = { age: 18, getAge: function () { return this.age } } let obj 阅读全文
posted @ 2021-02-16 14:48 懒懒同学不懒 阅读(247) 评论(0) 推荐(0)
摘要: instanceof 原型链查找 const arr1 = [1, 2, 3] const obj = { a: 1 } console.log(arr1 instanceof Array) //true console.log(obj instanceof Array) //false Array 阅读全文
posted @ 2021-02-15 11:09 懒懒同学不懒 阅读(351) 评论(0) 推荐(0)
上一页 1 2 3 4 5 6 7 8 ··· 13 下一页