原型模式

2016-04-12  本文已影响0人  niumew
// 图片轮播
var LoopImage = function(imageArr, container) {
    this.imageArr = imageArr;
    this.container = container;
}
LoopImage.prototype = {
    createImage : fucntion() {
      
    },
    changeImage : fucntion() {
      
    }
}

// 上下滑动类
var SlideLoopImg = function(imageArr, container) {
    LoopImage.call(this, imsgeArr, container);
}
SlideLoopImg.prototype = new LoopImage();
SlideLoopImg.prototype.changeImage = function() {
    
}

// 渐隐切换类
var FadeLoopImg = function(imageArr, container, arrow) {
    LoopImage.coll(this, imageArr, container);
    this.arrow = arrow;
}
FadeLoopImg.prototype = new LoopImage();
FadeLoopImg.prototype.changeImage = function() {
    
}

原型继承##

function prototypeExtend() {
    var F = function() {},
          args = arguments,
         i = 0,
         len = args.length;

    for (; i<len; i++) {
        for (var j in args[i]) {
            F.prototype[j] = args[i][j];
         }
    }
    return new F();
}

// 一个实例
var book = prototypeExtend({
    name: 'duku1501',
    price : function() {
        console.log(this.name + 'price:30.00');
    }
},{
    readTime : function(name) {
      console.log(this.name + "1hours");
},{
    readPlace : function() {
       console.log("home")
    }
})

book.price();
book.readTime(duku1501);
book.readPlace();
上一篇下一篇

猜你喜欢

热点阅读