重绘:当节点需要更改外观而不会影响布局。
回流:DOM 结构的修改引发DOM 几何尺寸变化的时候,发生回流。
常见的几何属性有width、height、padding、margin、left、top、border 或者是DOM 节点发生增减移动。
减少重绘和回流的办法。
使用css3新增属性:translate替代top等方向值。
避免频繁使用style,而是采用class 。
普通函数this :
this 总是代表它的直接调用者。
在默认情况下,没找到直接调用者,this 指的是window。
在严格模式下,没有直接调用者的函数中的this 是undefined 。
使用call, apply, bind绑定,this 指的是绑定的对象。
箭头函数this :
在使用 => 定义函数的时候,this 的指向是 定义时所在的对象,而不是使用时所在的对象;
不能够用作构造函数,这就是说,不能够使用new 命令,否则就会抛出一个错误;
不能够使用 arguments 对象;
不能使用 yield  命令;
 
var  没有块级作用域,支持变量提升。
let  有块级作用域,不支持变量提升。不允许重复声明,暂存性死区。不能通过window. 变量名进行访问. 
const  有块级作用域,不支持变量提升,不允许重复声明,暂存性死区。声明一个变量一旦声明就不能改变,改变报错。
创建一个对象
连接原型
绑定this 
返回该对象
function  _new ( ) { 
  let  obj =  new  Object ( ) ; 
  let  Con =  [ ] . shift . call ( arguments) ; 
  obj. __proto__ =  Con . prototype; 
  let  result =  Con . apply ( obj, arguments) ; 
  return  typeof  result ===  'object'  ?  result :  obj
} 
原型链:每个被实例对象都有__proto__对象,它指向了构造该对象的构造函数的prototype属性。同时该对象可以通过__proto__对象来寻找不属于自身的属性,
原型:就是实现继承过程中产生的一个概念。
原理是:复制父类的属性和方法来重写子类的原型对象
原型继承
构造函数继承
组合继承
寄生继承
寄生组合继承
class 
等等
function  Father ( ... arr)  { 
    this . some =  '父类属性' ; 
    this . params =  arr; 
} 
Father . prototype. someFn  =  function ( )  { 
    console. log ( 1 ) ; 
} 
Father . prototype. someValue =  '2' ; 
function  Son ( )  { 
    Father . call ( this ,  'xxxx' ) ; 
    this . text =  '2222' ; 
} 
Son. protptype =  Object. create ( Father . prototype) ; 
Son . prototype. constructor =  Son; 
Object. _create  =  function ( obj ) { 
  function  F ( ) { } ;  
  F . prototype =  obj;  
  return  new  F ( ) ;  
} 
闭包就是有权访问一个函数内部变量的函数,也就是常说的函数内部嵌套函数,内部函数访问外部函数变量,从而导致垃圾回收机制没有将当前变量回收掉。这样的操作,有可能会带来内存泄漏。好处就是可以设计私有的方法和变量。
js拥有特殊的垃圾回收机制,当一个变量在内存中失去引用,js会通过特殊的算法将其回收,并释放内存。
分为以下两个阶段:
标记阶段:垃圾回收器,从根对象开始遍历,访问到的每一个对象都会被标示为可到达对象。
清除阶段:垃圾回收器在对内存当中进行线性遍历,如果发现该对象没有被标记为可到达对象,那么就会被垃圾回收机制回收。
这里面牵扯到了引用计数法,每次引用都被会‘➕1 ’ 如果标记清零,那么就会被回收掉。
浅拷贝
	通常需要拷贝的对象内部只有一层的这种对象。
	常用的方法
	Object. assign方法来实现
	扩展运算符 ... obj
深拷贝
	通常是嵌套二层或以上的复杂对象
	常用方法
	JSON . parse ( JSON . stringfy ( object) ) ;  该方法忽略掉undefined 、忽略Symbol、忽略function 。只适合简单深拷贝
	手写递归方法去实现。
	通过第三方库提供的深拷贝实现。
防抖函数:将多次触发变成最后一次触发;
function  debounce ( fn, wait ) { 
  let  timer =  null ; 
  return  function  ( ) { 
    let  arg =  arguments; 
    if ( timer) { 
      clearTimeout ( timer) ; 
      timer =  null ; 
    } 
    timer =  setTimeout ( ( ) => { 
       fn . apply ( this , arg) 
    } , wait) 
  } 
} 
function  clg ( ) { 
  console. log ( 'clg' ) 
} 
window. addEventListener ( 'resize' , debounce ( clg, 1000 ) ) 
function  throttle ( fn, time ) { 
  let  lastTime =  null ; 
  return  function ( ) { 
    let  nowTime =  Date. now ( ) ; 
    if ( nowTime -  lastTime >  time ||  ! lastTime) { 
      fn ( ) ; 
      last =  nowTime
    } 
  } 
} 
function  sayHi ( ) { 
  console. log ( 'hi' ) 
} 
setInterval ( throttle ( sayHi, 1000 ) , 500 ) 
相同点:都是重定向this 指针的方法。
不同点:call和apply的第二个参数不相同,call是若干个参数的列表。apply是一个数组
手写一个call方法
let  mock =  {  value :  1  } ; 
function  mockNum ( ) { 
 console. log ( 'value' , this . value) 
} 
mockNum . call ( mock)  
转换一下实现方法就是
let  mock =  { 
  value: 1 ; 
  mockNum : function ( ) { 
     console. log ( 'value' , this . value) 
  } 
} 
mock. mockNum ( ) ; 
所以经过上面这个操作的演化而来的结果就是如下步骤:
1.  将函数设为一个对象的属性
2.  并将这个函数的属性调用
3.  删除该函数
Function . prototype. Mycall  =  function ( context ) { 
  let  obj =  context ||  window; 
  obj. fn =  this ;  
  let  args =  [ ... arguments] . slice ( 1 ) ;  
  let  result =  obj. fn ( ... args) ;  
  delete  obj. fn; 
  return  result; 
} 
let  mock =  {  value :  1  } ; 
function  mockNum ( ) { 
  console. log ( 'value' , this . value) ; 
} 
mockNum. Mycall ( mock)  
Function . prototype. Myapply  =  function  ( context ) { 
    let  obj =  context ||  window; 
    obj. fn =  this ; 
    let  result =  arguments[ 1 ]  ?  obj. fn ( arguments[ 1 ] )  :  obj. fn ( [ ] ) ; 
    delete  obj. fn; 
    return  result; 
} 
let  mock3 =  { 
  arr:  [ 1 ,  2 ,  3 ,  4 ,  5 ] , 
} ; 
function  arrx2 ( arr )  { 
  return  this . arr. concat ( arr) . map ( ( x )  =>  x *  2 ) ; 
} 
console. log ( "arrx2" ,  arrx2. myApply ( mock3) ) ; 
bind方法是直接返回一个新的函数,需要手动去调用才能执行。
创建一个新函数,当这个新函数被调用时,bind ( ) 方法的第一个参数将作为运行他的this ,之后的一系列参数将会在传递的实参传入作为他的参数;
特点:1.  返回一个函数。 2.  可以传入参数;
手写一个bind方法
例如:
let  foo =  {  value :  1  } ; 
function  bar ( )  { 
  console. log ( 'bindFoo' , this . value) ; 
  
} 
let  bindFoo =  bar . bind ( foo) ; 
bindFoo ( )  
Function . prototype. Mybind  =  function ( obj ) { 
  if ( typeof  this  !==  'function' )  throw  new  Error ( 'not a function' ) ; 
  let  self =  this ; 
  let  args =  [ ... arguments] . clice ( 1 ) ; 
  return  function  F ( ) { 
    if ( this  instanceof  F ) { 
      return  new  self ( ... args, ... arguments) ; 
    } 
    return  self . apply ( obj, args. concat ( [ ... arguments] ) ) ; 
  } 
} 
作为一个正常的函数调用
函数作为方法调用
使用构造函数调用函数
作为函数方法调用函数
捕获:就是从根元素开始向目标元素递进的一个关系;从上而下
冒泡:是从目标元素开始向根元素冒泡的过程;想象一下水里的泡泡从下而上。
⚠️stopPropagation 通常理解它是用来阻止事件冒泡的,其实该函数也可以阻止捕获事件。
instanceOf用来判断右边的prototype是否在左边的原型链上,告诉我们左边是否是右边的实例。
function  instanceof ( left,  right )  { 
    
    let  prototype =  right. prototype
    
    left =  left. __proto__
    
    while  ( true )  { 
        if  ( left ===  null ) { 
            return  false   
        } 
        if  ( prototype ===  left) { 
            return  true 
        } 
        left =  left. __proto__
    } 
} 
typeof  检测对象,除开函数是function 类型之外。像常见的数组,对象或者是正则, 日期等等都是object;
需要注意一下:
typeof  Symbol ( )  
typeof  null  
typeof  undefined  
typeof  null 检测输出object因为js最初版本,使用的是32 位系统,类型的标签存储在每个单元的低位中000 是object类型。null 全是0 ,所以当我们使用typeof 进行检测的时候js错误的判断位object
cookie	4 kb左右	每次都会携带在HTTP 头中,如果使用cookie保存过多数据会带来性能问题	默认是关闭浏览器后失效,  但是也可以设置过期时间
localstorage	5 M	仅在浏览器中保存,不参与和服务器的通信	除非手动被清除,否则永久保存
SessionStorage	5 M	仅在浏览器中保存,不参与和服务器的通信	仅在当前会话 ( 窗口) 下有效,关闭窗口或浏览器后被清除,  不能设置过期时间
目前暂时已知的跨域方法是:
jsonp跨域,原理:script标签没有跨域限制的漏洞实现的一种跨域方法,只支持get 请求。安全问题会受到威胁。
cors跨域,通过后端服务器实现,Access- Control- Allow- Origin。
postMessage window的一个属性方法。
websocket
nginx反向代理
iframe跨域
首先需要明白webpack proxy跨域只能用作与开发阶段,临时解决本地请求服务器产生的跨域问题。
并不适合线上环境。配置在webpack的devServer属性中。
webpack中的devsever配置后,打包阶段在本地临时生成了一个node服务器,浏览器请求服务器相当于请求本地服务。
广度优先:尝试访问尽可能靠近它的目标节点,然后逐层向下遍历,直至最远的节点层级。
深度优先:从起始节点开始,一直向下找到最后一个节点,然后返回,又继续下一条路径。知道找遍所有的节点。
一般会用到url重写的技术来进行会话跟踪,每一次的交互,都会在url后面加上sid= xxx类似的参数。服务端根据这种方式来识别用户。
setTimeout表示间隔一段时间之后执行一次调用,而setInterval是每隔一段时间循环调用,直至清除。
内存方面,setTimeout只需要进入一次宏队列,setInterval不计算代码执行时间,有可能多次执行多次代码