随笔分类 -  JavaScript

TypeScript 基础类型的使用,类型断言的使用
摘要://使用unknown,可以给变量添加任何的类型值 //在使用时必须需要断言如下 let e:unknown; e = 'hello' let s :string; //断言的三种方式 //方式一 if(typeof e 'string'){ s = e console.log(s); } //方式 阅读全文

posted @ 2022-12-13 16:33 totau 阅读(50) 评论(0) 推荐(0) 编辑

javascript 执行上下文
摘要:<script> //执行上下文,顺序执行到此出 会产生一个全局的执行上下文(ECG),并把全局ECG放到ECS(执行上下文栈)中 // VO:GO (globan object) 对浏览器而言, window 即使GO // 声明的函数,函数声明在堆空间中,栈记录次函数在堆中的空间地址 0x666 阅读全文

posted @ 2022-11-26 22:43 totau 阅读(22) 评论(0) 推荐(0) 编辑

JavaScript的this指向
摘要:1、结论:js中的this 是当前方法所属的对象 'use strict' let obj = { name:'taotao', myName(){ return this } } console.log(obj.myName()) // {name: 'taotao', myName: ƒ} fu 阅读全文

posted @ 2022-11-24 17:01 totau 阅读(9) 评论(0) 推荐(0) 编辑

js 深度拷贝递归生成
摘要:function deepClone(param){ //判断时间 if(param instanceof date) return new Date(param); //如果普通类型直接返回 if(typeof param !== 'object') return param; //如果是则直接回 阅读全文

posted @ 2022-11-24 13:01 totau 阅读(22) 评论(0) 推荐(0) 编辑

箭头函数的this 指向
摘要:let p ={ num:1, add: function(a){ let f = v => { //箭头函数没有this,往上找一层的this 就是箭头函数的this // 箭头函数没有this 不能用call apply bind 进行绑定 console.log(this) return v 阅读全文

posted @ 2022-11-23 16:36 totau 阅读(20) 评论(0) 推荐(0) 编辑

undefin 出现的情况
摘要:1 ) 访问不存在的变量时 2)访问对象不存在的属性时 3)访问数组中不存在的索引 4)形参没有赋值 5)函数没有返回值时 默认返回undefine 6)解构不成功返回的undefine 阅读全文

posted @ 2022-11-22 23:30 totau 阅读(44) 评论(0) 推荐(0) 编辑

JavaScript中的bind使用技巧
摘要:function f() { return this.a; } //bind绑定会创一个与f具有相同函数体和作用域的新函数,在这个新函数中,this将会永久的绑定第一个参数。 var g = f.bind({ a: 'taotao' }); console.log(g()); //taotao va 阅读全文

posted @ 2022-10-21 16:02 totau 阅读(40) 评论(0) 推荐(0) 编辑

javascript 的setTimeOut 中this指向及外部参数传参
摘要://外部的参数传参数,放到第三项及以后就可以 myArray = ['zero', 'one', 'two']; myArray.myMethod = function (sProperty) { console.log(arguments.length > 0 ? this[sProperty] 阅读全文

posted @ 2022-10-21 12:28 totau 阅读(121) 评论(0) 推荐(0) 编辑

JavaScript数组常用数组函数
摘要:const arr = [1,12,13,4,5,6,7,8]; //找出符合条件的第一个元素,并返回。 否返回undefined const fount = arr.find((x)=>{ return typeof(x) "number"; }) console.log('查找-find ', 阅读全文

posted @ 2022-10-19 13:33 totau 阅读(39) 评论(0) 推荐(0) 编辑

JavaScript es8 async
摘要:1 async函数 返回一个promise类型 2 promis类型有返回的结果决定async结果 3, async 里面可以不用包含await async function aa(){ //返回值是个非promise的值,则此方法返回的状态(fulfilled),且返回值是1 //return 1 阅读全文

posted @ 2022-09-16 23:46 totau 阅读(39) 评论(0) 推荐(0) 编辑

javascript 集合 交集 并集 差集
摘要:let arr1 = [1,2,7,4,9,5,3,2] let arr2 = [2,3,5,6] //去重利用集合,并返回数组 let uniq = [...new Set(arr1)] console.log(uniq); //求交集 let jiaoji = arr2.filter(item= 阅读全文

posted @ 2022-09-16 17:24 totau 阅读(66) 评论(0) 推荐(0) 编辑

es6 生成器
摘要:15:26:46//生成器 function getUser(){ setTimeout(()=>{ let data = '涛涛'; //第二次的next() 执行可以返回第一次的执行的结果,同时接着执行下一个迭代函数getOrder iterator.next(data) }, 1000) } 阅读全文

posted @ 2022-09-16 14:18 totau 阅读(20) 评论(0) 推荐(0) 编辑

JavaScript的普通函数,箭头函数作用域的区别
摘要:<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style> #ad { width: 200px; height: 200px; background: #58a; } </s 阅读全文

posted @ 2022-09-15 17:19 totau 阅读(22) 评论(0) 推荐(0) 编辑

自定义构造函数的原型对象及原型链
摘要:<script> //只要创建了新函数,就会根据一组特定的规则为该函数创建一个 prototype 属性,//这个属性指向函数的原型对象function Person(){}Person.prototype.name='taotao';Person.prototype.age=18;Person.p 阅读全文

posted @ 2022-09-13 15:29 totau 阅读(23) 评论(0) 推荐(0) 编辑

JavaScript原型对象动态性
摘要:function的原型对象的动态性 <script> //创建一个自定义构造函数 function Person(){ } //通过new 关键字获取到函数的对象//此时的obj变量内容是一个指向 function Person() 构造函数的原型对象(__proptype__)的地址var obj 阅读全文

posted @ 2022-09-13 07:46 totau 阅读(21) 评论(0) 推荐(0) 编辑

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示