js-设计模式

Author Avatar
zongyuan 6月 11, 2018 【字数:121】 【阅读时长:1min】
  • 在其它设备中阅读本文章

36个设计模式

面向对象编程

类的实现(es5)
var Book = function(name) {
    var id = 1; // 私有变量
    var getId = function() {
        console.log(id)
    }; // 私有方法
    this.name = name; // 公有变量
    this.setName = function(name) {
        this.name = name;
    } // 公有方法
}
Book.prototype = {
    price: 100, // 静态公有属性
    getPrice: function() {
        console.log(this.price);
    } // 静态公有方法
}

闭包是有权访问另外一个函数作用域中变量的函数,即在一个函数内部创建另一个函数

简单工厂模式

感谢阅读 thx~
本文链接:https://627235655.github.io/2018/06/11/js-design-mode/