JavaScript: OO

From mmmv_kos
Jump to: navigation, search

Pärimine

stackoverflow.com viide 1 stackoverflow.com viide 2

window.fffsuper=function(){
    var self_public_=this;
    this.s_aa=function(){return 'AA';}
} 

window.fffsub=function(){
    var self_public_=this;
    this.s_bb=function(){
        var s_out='bb_'+self_public_.s_aa();
        return s_out;
    }
} 

window.fffsub.prototype=new window.fffsuper();
var ob=new fffsub();
var s_0=ob.s_bb();

document.write('s_0=='+s_0);


Rakendub skoobipõhine otsimine:

window.fffsuper=function(){
    var self_public_=this;
    this.s_say=function(){return 'moo!';}    

    this.s_fairitale=function(){
        var s_out='Creature says:'+self_public_.s_say();
        return s_out;
    }
} 
 
window.fffsub=function(){
    var self_public_=this;
    this.s_say=function(){return 'meow!';}    
} 
 
window.fffsub.prototype=new window.fffsuper();
var ob=new fffsub();
var s_0=ob.s_fairitale();
 
document.write('s_0=='+s_0); // returns: s_0==Creature says:moo!