随笔分类 - JavaScript
摘要:call, apply, bind 主要实现的功能是改变this的指向. 在正常情况下 console.log(this) 输出的内容是 window 对象 第一个call函数 <script> // 改变函数内this指向 js提供了三种方法 call() apply() bind() var o
阅读全文
摘要:extends用法演示 <script> class Father{ constructor(x, y){ this.x = x; this.y = y; } sum(){ console.log(this.x + this.y) } } class Son extends Father{ cons
阅读全文
摘要:原型: <script> // 构造函数 function Star(uname, age){ this.uname = uname; this.age = age; this.dance = function(){ console.log("跳舞"); } } Star.prototype.sin
阅读全文
摘要:<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>pagination-nick</title> <style> button{ padding:5px; margin:5px; } .active-nick{ color:red
阅读全文
摘要:在js中函数有上到下执行,变量提升即使var a 会在函数赋值前,先一步声明变量 ,也就是说 console.log(a) 会输出 undefined <script> console.log(a) var a = 8<script> 函数提升写下函数的时候 fun();写在function fun
阅读全文
摘要:JS是单线程的语言,它的异步同步是通过 Event Loop实现的,分为三个栈,调用栈、消息队列(宏任务)、微任务。 js执行的时候调用DOM遇到第一个函数的时候会把函数压入栈。 function fn2(){ console.log(2) } fn2() fu2()会压入栈 执行function
阅读全文
摘要:语法: new Promise((resolve, reject)=>{}) new Promise(function(){}) Promise也是异步的结果,promise有三个阶段 pending、fulfilled、rejected。promise只有两种结果pending变为fulfille
阅读全文
摘要:防抖和节流 防抖 准备工作 获取id值再改id上添加监听点击事件 难点一 要在一个函数调用另外的一个函数return 里面 第二clearTimeout 和setTimeout 由于要清除时间所以定义变量的时候要将变量写在return上面, 第三在里面写如apply将return里面的函数的this
阅读全文
摘要:JavaScript数组去重这里写了两种方法 第一种 var Arr = [1,2,3,4,5,6,6,5] function uniArr(arr){ return [...new Set(arr)] } 第二种 数组双循环 var Arr = [1,2,3,4,5,6,6,5] function
阅读全文
摘要:function a(){ console.log('aaa') } 直接调用为 a() var b = function(){ console.log('bbb') } 直接调用为b() a()能在写在function a(){}上面而b()不能 var c = { c:function (a){
阅读全文
摘要:function DOG(name){ this.name = name; this.species = '犬科' } var dogA = new DOG('大毛'); var dogB = new DOG('二毛'); dogA.species = '猫科'; console.log(dogB.
阅读全文
摘要:Object.defineProperty的功能就是在现有的属性进行修改或添加 let Person ={} Person.name = 'Tom' 等于 let Person = {} Object.defineProperty(Person, 'name',{ value: 'jack', co
阅读全文
摘要:一、(我认为的)常规复杂的方式 function createPerson(name, sex){ var obj = {} obj.name = name obj.sex = sex return obj } var admin = createPerson('xiaoming', 18) con
阅读全文