js要点总结

2019-06-11  本文已影响0人  狗蛋儿妈妈爱coding

<1> 设计模式原则 solid

S && O && L && I && D

  1. s single 单一职责 原则 一个类只能有一个让它变化的原因。即,将不同的功能隔离开来,不要都混合到一个类中
  2. o open closed 开放封闭原则 扩展开放 修改封闭
  3. l Liskov Liskov原则 子类可以完全覆盖父类
  4. i interface 接口隔离原则 一个接口负责单一功能 不出现胖接口 当有新的功能需求 则增加新的接口 而不在已有接口上面加功能导致胖接口
  5. d dependency 依赖倒置原则

<2> 函数提升 && 变量提升

1、函数提升 会把整个函数提升到前面 而变量提升只是提升声明 不提升赋值
2、只有函数声明形式才会得到提升
例子:function a(){ ...}可以得到提升;
而 var a = function(){...}则得不到提升。
3、测试
function say(){
function name(){
console.log('frog')
}
return name();
function name(){
console.log('hello')
}
}
var name = say();

<3> 闭包的返回方式

1、函数作为返回值被返回
2、函数作为参数被传递

<4>prototype原型链

       function Atest(){};
       Atest.prototype.aaa = 'first value';
       var a = new Atest();
       Atest.prototype.aaa = 'b value';
       a.aaa = 'a value';
       var b = new Atest();
      
       // console.log(Atest.prototype.aaa);
       console.log(a.aaa);  //a value
       console.log(b.aaa);  //b value
上一篇 下一篇

猜你喜欢

热点阅读