20201014赵鑫
学习总结
节流与防抖
当遇到某些事件时,如scroll和mousemove等,浏览器频繁的被触犯,会导致对应的事件也会很频繁的被触发,这样就会使得浏览器的资源消耗很大,此时就需要方法来解决。
节流:
节流就是为该事件设置一个阀门,阀门多久才能打开一次让事件执行,其余时间阀门关闭。
防抖:
防抖就是让该事件多久没有触发了,然后执行一次。
//防抖
function fangdou(ev,ms){
let timer = null;
return function(){
if(timer){
clearTimeout(timer);
// timer = setTimeout(ev,ms)
}
// clearTimeout(timer);
timer = setTimeout(ev,ms)
}
}
function say1(){
console.log('我是防抖')
}
window.addEventListener('mousemove',fangdou(say1,1000))
//节流
function jieliu(ev,ms){
let flag = true
return function(){
if (!flag) return
flag = false
setTimeout(function(){
ev();
flag = true
},ms)
}
}
function say2(){
console.log('我是节流')
}
window.addEventListener('mousemove',jieliu(say2,1000))
ES5新特性
严格模式(use strict)
严格模式,使得JavaScript在更严格的语法条件下运行。
①变量声明必须使用var
②禁止自定义函数中的this指向window
③创建块级作用域
④对象不能有重名属性
增加JSON对象
JSON.stringify()
JSON.parse()
对象增加了getter和setter属性
ES6新特性
let
const
允许函数参数设置默认值
箭头函数
class关键字定义类
结构赋值(对象或者数组)
等
Promise
var promise = new Promise(function(resolve,reject){
setTimeout(function(){
if(true){
resolve( '成功')
}else{
resolve('失败')
}
},1000)
})
promise.then(function(data){
alert(data)
}).catch(function(err){
alert(err)
});
VUE双向绑定原理
<div id="app">
<input type="text" id="txt" />
<p id="show"></p>
</div>
<script>
var obj = {}
Object.defineProperty(obj,'txt',{
get:function(){
return obj
},
set:function(newValue){
document.getElementById('txt').value = newValue
document.getElementById('show').innerHTML = newValue
}
})
document.addEventListener('keyup',function(e){
obj.txt = e.target.value
})
</script>
学习心得
书山有路勤为径,学海无涯苦作舟。今天尝试了一下MongoDB,这是一个我没有接触过的数据库,但是刚开始用就喜欢上了它,想要去学习它,可以又发现需要学的东西太多了,想要学的东西也太多了,所以说只能尽可能的抽出时间去学习更多知识,才能让自己变强。
点赞
评论留言