继承实例

继承实例

//定义产品对象
function Base(){
    /*产品名称*/
    this.name=''
    this.description=''
    /*普通价格*/
    this.normalPrice=144
    /*团购价格*/
    this.youhuijia=120
    /*已经购买的人数*/
    this.buySum=100;
    /*轮播图片列表*/
    this.images=[]
}
Base.prototype={
    init:function(){},
    /*普通购买*/
    buy:function(){},
    /*绑定图片列表*/
    bindDOMImage:function(){
        var str=''
        for(var i= 0,len=this.images.length;i'
            str+=''
            str+=''
        }
        $('#etalage').html(str)

        /*jquery插件实现的幻灯片特效*/
        $('#etalage').etalage({
            thumb_image_width: 250,
            thumb_image_height: 300,
        });
    },
    /*绑定详细信息*/
    bindDOMDetail:function(){},
    /*绑定事件*/
    bindEvents:function(){},
    /*团购*/
    groupBuy:function(){},
}

/*衣服*/
var Close = function(){
    Base.call(this, arguments);
    this.sizes=['X','XL','XXL']
    this.colors=['黄色','红色']
}
/*原型写法*/
Close.prototype = new Base();
Close.prototype.bindDOMDetail= function(){}
Close.prototype.bindSizes = function(){
}
Close.prototype.bindColors = function(){
    var str= ''
    str+= '

颜色

' for(var i=0;i' } $('.colors').html(str) } Close.prototype.init= function(){ this.bindDOMDetail() this.bindDOMImage() this.bindSizes() this.bindColors() } /*书籍*/ var Book = function(){ Base.call(this, arguments); this.author='糖葫芦' this.publisher = '清华大学出版社' this.pages = 333 this.publishTimes = 2 this.type='IT教育' this.publishTime='2016-09-09' } /*原型写法*/ Book.prototype = new Base(); /*重写 覆盖基类方法*/ Book.prototype.bindDOMDetail= function(){} Book.prototype.readTry= function(){} Book.prototype.readAll= function(){} Book.prototype.init= function(){ this.bindDOMDetail() this.bindDOMImage() } /*不能使用如下写法*/ //Book.prototype = {} /*为什么 因为这个写法相当于重新定义一个原型对象*/

你可能感兴趣的:(继承实例)