- 博客(6)
- 收藏
- 关注
原创 js中函数声明方式
函数声明方式差别1.function 函数名() 2.var 变量名 = function() 3. new Function()如果要明白函数声明的方式不一样,就必须要搞懂js的变量提升,js会先提升var 的变量提升到代码最上面,然后才会提升function,var hello = function hello(){ console.log('嘻嘻') } function hello(){ console.log('哈哈') } hello()//嘻嘻 he
2021-05-19 14:51:01
205
原创 Array.filter
filter用于对数组进行过滤。它创建一个新数组,新数组中的元素是通过检查指定数组中符合条件的所有元素。返回值是这个数组中所有符合条件的元素,所组成的新数组。语法filter(function(item,index,array){})传入一个函数,可以是箭头函数,函数的形参依次是,循环的项,下标,调用的数组。如果返回值是布尔总true,那么将返回当前项array =[1,2,3,4]const res = array.filter(v => true)console.log(r
2021-05-17 19:52:50
958
原创 js对象中的getset
对象的get和set方法。可以监听一个属性的取值和赋值。//如果一个这个值还没有被赋值,取值的是后想显示这个值就会报错var obj = { a:1, get b(){ console.log('b被取值了' + b) }, set b(sb){ b = sb console.log('b被赋值为'+sb) } } obj.b obj.b= 11 //报错:Uncaught ReferenceError: b
2021-05-12 20:55:55
524
原创 Array.sort()方法
sort方法可以传入一个函数,不是必选参数,如果不传入函数的话,那么排序只适合个位数的排序。排序会将元素转化成字符串,再根据Unicode位点进行排序。不给sort()传入方法比较数值let arr =[1,20,1000,80,705,33,21] console.log(arr.sort()) // [1, 1000, 20, 21, 33, 705, 80]给sort(function(a,b){})方法传出一个函数,内部会有循环机制,每次会将相邻的两个元素传给a和b,如果执行循环
2021-05-08 15:37:57
432
原创 ES6中getOwnPropertyDescriptors实现
运用了es5的getOwnPropertyDescriptor//方法的实现 function getOwnPropertyDescriptors(obj){ const result = {} // console.log(Reflect.ownKeys(obj)) for(let key of Reflect.ownKeys(obj)){ result[key] = Object.getOwnPropertyDescrip
2021-04-22 23:04:23
142
原创 multer简单使用
node中multer包的使用//这样可以保留导入图片的文件名const storage = multer.diskStorage({ destination:'./uploads', filename(req,file,cb){ cb(null,Date.now() + extname(file.originalname)) }})const uploader = multer({ storage, // 通过这个方法,可以对上传的文件进
2021-04-21 22:46:40
796
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅