Skip to content

Instantly share code, notes, and snippets.

@zhannes
Created December 11, 2012 16:17
Show Gist options
  • Save zhannes/4259920 to your computer and use it in GitHub Desktop.
Save zhannes/4259920 to your computer and use it in GitHub Desktop.
js inheritance example
/* for commented version, see https://gist.github.com/4259920/95d6d741d227c274be1ecf5238998c01f3658131 */
function object(o){
function ctor(){}
ctor.prototype = o;
return new ctor;
}
function inheritProto(subType,superType){
var prototype = object(superType.prototype);
prototype.constructor = subType;
subType.prototype = prototype;
}
function Carousel(){}
Carousel.prototype = {
config: function(){},
transition: function(el,pos){},
_config: function(){ /* definition left out */ },
goTo: function(pos){
if(pos >= this.numSlides || pos < 0 ) return;
this.activeSlide = pos;
this.transition(this.transitionEl,pos);
},
init: function(el,options){
if(!el) return;
this.el = el;
this.options = options || {};
this.$el = $(el);
this.transitionEl = this.options.transitionEl || this.$el;
this.transitionAlg = this.options.transitionAlg || function(pos){
return pos*-100;
};
this._config();
this.config();
}
};
function VCarousel(){
Carousel.apply(this,arguments);
}
inheritProto(VCarousel, Carousel);
$.extend(VCarousel.prototype, {
config: function(){ /*define*/ },
transition: function(){ /*define*/ }
});
var vc = new VCarousel;
vc.init($('.slides'), {
controls: $('#controls').find('.prev,.next'),
easing: 'cubic-bezier(1.000, 0.000, 0.000, 1.000)',
transitionProperty: 'top',
transitionDuration: '1s'
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment