美文网首页
js设计模式

js设计模式

作者: igor_d140 | 来源:发表于2018-08-22 20:41 被阅读6次

1、工厂模式

//用函数来封装特定接口创建对象细节,抽象创建具体对象的过程

function createProduct(name, price, description) {

    let product = new Object()

    product.name = name;

    product.price = price;

    product.description = description;

    return product;

}

function createProduct(name, price, description) {

    return {

        name: name,

        price: price,

        description: description

    }

}

var oneYearCard = createProduct('秦桥云阅读年卡', 300, '秦桥云阅读卡,免费畅读一年畅读类书籍')

var oneMonthCard = createProduct('秦桥云阅读月卡', 30, '秦桥云阅读卡,免费畅读一个月畅读类书籍')

相关文章

网友评论

      本文标题:js设计模式

      本文链接:https://www.haomeiwen.com/subject/rxfuiftx.html