js设计模式

2018-08-22  本文已影响6人  igor_d140

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, '秦桥云阅读卡,免费畅读一个月畅读类书籍')

上一篇下一篇

猜你喜欢

热点阅读