![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
javascript
javascript 知识点分享
清云小程序
这个作者很懒,什么都没留下…
展开
-
对象操作的 14 种方法
定义一个 obj 对象var obj = {a: 1, b: 2}1、获取原型 [[GetPrototypeOf]]// 以下 3 种方式都获取到了 obj 的原型,但是只有第一种是函数式方法,是 js 内置提供的方法,推荐使用第一种console.log(Object.getPrototypeOf(obj))console.log(obj.__proto__)console.log(Object.prototype)2、设置原型 [[SetPrototypeOf]]Ob.原创 2021-06-25 10:23:47 · 1833 阅读 · 0 评论 -
ES6 的代理 Proxy
Proxy 代理对象const target = { a: 1}const proxy = new Proxy(target, { get(target, property) { return target[property] }, set(target, property, value) { target[property] = value return true // 严格模式下需要返回 true,否则会报错 }})console.log...原创 2021-06-25 09:11:26 · 94 阅读 · 0 评论 -
javascript 模块化
模块化的代码实现let module = (function () { const moduleList = {} function define(name, modules, action) { modules.map((module, index) => { modules[index] = moduleList[module] }) moduleList[name] = action.apply(n...原创 2021-06-22 22:51:48 · 121 阅读 · 1 评论 -
javascript 类 class
类的本质是函数class Father {}console.dir(Father)function Parent() {}console.dir(Parent)// Father 和 Parent 不管从结构还是原型,几乎一模一样,所以类的本质是函数(尤其指构造函数),类只是一种语法糖。console.log(typeof Father) // function成员变量(属性)class Father { constructor(a){ t...原创 2021-06-22 14:47:53 · 253 阅读 · 0 评论 -
javascript 原型(一)
原型的初步理解const arr = [1, 2, 3]console.log(arr) // 打印 arr 数组,发现并没有 concat 函数console.log(arr.concat([4, 5, 6])) // 然而却可以使用 arr.concat(),为什么?// 原因是,arr 下面还有个 __proto__ 属性,__proto__下面存在 concat 方法。// __proto__ 相当于 arr 的爸爸,__proto__ 拥有的方法和属性都可以被 arr 使用。//原创 2021-06-21 15:41:50 · 71 阅读 · 0 评论 -
javascript this 指向问题(隐式绑定、显示绑定、箭头函数)
四种绑定规则1、默认绑定规则:this 指向 window。2、隐式绑定规则:谁调用就指向谁。3、显式绑定规则:this 指向 call、apply、bind 函数的第一个传参。4、new 绑定规则:this 指向构造函数产生的对象。1、默认绑定规则// 全局中的 this 指向 windowconsole.log(this === window) // true// 函数独立调用,函数内部的 this 指向 windowfunction func() { ...原创 2021-06-18 15:40:10 · 262 阅读 · 0 评论 -
javascript深浅拷贝的原理和实现
深浅拷贝由来// 正常情况,a 值的改变不影响 blet a = 1let b = aa = 2console.log(b) // 1// 不正常,a 中元素的改变影响了 blet a = [1, 2, 3]let b = a // 引用a[0] = 4console.log(b[0]) // 4// 不正常let a = {name: 'sam'}let b = aa.name = 'jack'console.log(b.name) // 'jack'说明原创 2021-06-18 09:36:45 · 169 阅读 · 0 评论 -
javascript 严格模式与普通模式的区别
使用严格模式"use strict"区别变量1、变量使用前必须要声明。2、不能直接对变量操作 delete,由静默失败变成报错。对象1、属性描述符(除了 enumerable)出现不当操作的时候,由静默失败变成报错。函数1、参数是唯一的,即参数不能重名。2、取消形参和实参的映射关系。(非严格模式下,如果形参设置了默认值,那么也会取消形参和实参的映射关系)3、不能使用 arguments.callee 和 caller。4、不允许使用 eva.原创 2021-06-18 10:08:06 · 153 阅读 · 0 评论 -
javascript 值类型判断注意事项
合并数组const arr1 = [1, 2, 3]const arr2 = [4, 5, 6]const arr3 = [...arr1, ...arr2]console.log(arr3) // [1, 2, 3, 4, 5, 6]替代 applyconst arr = [1, 2, 3]function func(arg1, arg2, arg3){ console.log(arg1 + arg2 + arg3) // 6}func(...arr)// 替代...原创 2021-06-18 09:40:38 · 57 阅读 · 0 评论 -
展开运算符的应用场景
合并数组const arr1 = [1, 2, 3]const arr2 = [4, 5, 6]const arr3 = [...arr1, ...arr2]console.log(arr3) // [1, 2, 3, 4, 5, 6]替代 applyconst arr = [1, 2, 3]function func(arg1, arg2, arg3){ console.log(arg1 + arg2 + arg3) // 6}func(...arr)// 替代...原创 2021-06-18 09:38:56 · 125 阅读 · 0 评论 -
callee 和 caller
callee定义arguments.callee,指向当前函数的引用。匿名函数和立即执行函数因为没有函数名,需要使用 callee 来返回当前函数名。function inner() { console.log(arguments.callee === inner)}inner() // truecaller定义function.caller,指向调用当前函数的函数的引用。function inner() { console.log(inne...原创 2021-06-18 09:37:43 · 109 阅读 · 0 评论 -
javascript 中的几种继承方式
原型链继承function Parent(){}const parent = new Parent()Child.prototype = parentfunction Child(){}Child.prototype.name = 'sun'const child = new Child()console.log(child)console.log(parent)特点1、来自原型对象的所有属性被所有实例共享,即,改变 Child.prototype.name,Parent原创 2021-06-18 09:34:43 · 105 阅读 · 0 评论 -
防抖节流的原理及方案
防抖防抖原理有些事件,比如鼠标移动、滚动条滚动、键盘键弹起、窗口大小改变等,一旦触发,就会在短时间内触发好几次,如果这时候进行计算或者ajax请求,就会浪费计算机资源,甚至导致卡顿、奔溃,因此要给事件触发加一个延迟处理。当事件触发时,如果已有定时器,那么就要清除已有的定时器,重新设置定时器,因此如果事件不停的触发,定时器就不停的被清除、重新设置,因此也就无法执行事件函数,直到事件不再触发,才会让定时器触发,执行定时器中的事件函数。为了改变函数体内的 this 指向,要用 func.apply(t原创 2021-06-18 09:28:41 · 304 阅读 · 0 评论