javascript-工厂模式创建

来源:互联网 发布:嵌入式编程入门 编辑:程序博客网 时间:2024/05/18 18:16
//工厂模式function createObject (bookName,bookNum,bookColor,bookPrice) {    var book = new Object();//创建对象    book.bookName = bookName;//添加属性    book.bookNum = bookNum;    book.bookColor = bookColor;    book.bookPrice = bookPrice;    book.strory = function  () {//添加方法        return this.bookName + this.bookNum + this.bookColor +this.bookPrice + '正在销售中。。。。';    }    return book;//返回对象方法}var b1 = createObject('西游记',1223,'红色',12);//创建对象alert(b1.strory());//打印对象
0 0