public

Results 12 comments of public

一般的事件机制是先从document到目标事件再从目标事件到document,事件一被称为捕获,事件2呗称为冒泡,为了节约性能我们一般采用冒泡的方式对事件来进行处理。 我们进行一个点击事件来弹出每个li标签的值: 1 2 var li = document.getElementById("ul").getElementByTagName("li"); for(let i=0; i

1.根据索引去重 function uniqcArr(arr){ var tep=[]; for(var i=0;i

- var 定义变量变量会提升,let const不会变量提升let 和 const 存在块级作用域 - let 和 var 声明一个变量, const 声明一个只读的常量,const一旦定义了不能修改 - let和const存在暂时性死区, 凡是在声明之前使用这些变量就会报错 - let 和 const 不允许在相同作用域内, 重复声明一个变量

节流是为了防止事件的频繁书法的一种方式,常用的事件包括 - 滚动加载,加载更多或滚到底部监听 - resize事件,鼠标事件,onmouseover,按钮点击事件 - 一般有两种方式:时间戳,定时器方式实现。 function throttle(func,delay){ var arg = argument; var context = this; var timer = null; if(!timer){ timer = settimeout(()=>{ func.apply(arg,context); timer = null; },delay)...

jsonp主要利用script标签的src属性,指向一个需要访问的地址并提供一个回调函数来接收。 function jsonp(data){ console.log(data)}

``` let onWatch =(obj,setBind,getLogger)=>{ let handler ={ get(target,property,receiver){ getLogger(target,property); return Reflect.get(target,property,receiver) }, set(target,property,value,receiver){ setBind(value,property); return Reflect.set(target,property,value) } } return new Proxy(obj,handler) } let obj={a:1} let p=onWatch( obj, (v,property)=>{ // console.log(${property},${v});...

function flatter(arr){ var result =[]; for(var i=0;i

谁调用的this,this就指向谁, 1.在函数体中,简单调用该函数时(非显示/隐士绑定下),严格模式下this绑定到undefined,否则绑定到全局对象window/global; 2.一般构造函数new调用,绑定到新创建的对象上; 3.一般call,applly,bind方法显示调用,绑定到指定参数的对象上; 4.箭头函数中,根据外层上下文绑定的this决定this指向。

`观察者模式又叫做发布—订阅模式,它定义对象间的一种一对多的依赖关系,当一个对象的状态发生改变时,所有依赖于它的对象都将得到通知和更新。观察者模式提供了一个订阅模型,其中对象订阅事件并在发生时得到通知,这种模式是事件驱动的编程基石,它有利益于良好的面向对象的设计。` function getMessage(){ let message={}; this.register=function(messageType){ if(typeof message[messageType]=='undefined'){ message[messageType]=[] }else{ console.log('消息已注册')} } //订阅 this.subScribe=function(messageType,func){ if(typeof message[messageType]!=='undefined'){ message[messageType].push(func)}else{ console.log('消息未注册,不能订阅')} } //发布 this.fire=function(messageType,arg){ if(typeof message[messageType]=="undefined"){ console.log('消息未注册不能发布') return false} let events={ type:messageType, arg:arg||{}...