Ciao.
Seguendo questo tutorial ho trovato questo snippet:
C'è un modo di ottenere la stessa cosaCodice PHP:<script language="JavaScript" type="text/JavaScript">
function DivA(){
// define object properties
this.div=document.createElement('div');
this.width='400px';
this.height='300px';
this.position='absolute';
this.top='10px';
this.left='10px';
this.padding='5px';
this.border='1px solid #000';
this.backgroundColor='#f00';
// define 'display()' method
this.display=function(){
this.div.style.width=this.width;
this.div.style.height=this.height;
this.div.style.position=this.position;
this.div.style.top=this.top;
this.div.style.left=this.left;
this.div.style.padding=this.padding;
this.div.style.border=this.border;
this.div.style.background=this.backgroundColor;
document.getElementsByTagName('body')[0].appendChild(this.div);
}
}
// derive a child object from DivA object
function DivB(){
// define object properties and override parent properties
this.width='500px';
this.height='200px';
this.position='absolute';
this.top='20px';
this.left='20px';
this.padding='10px';
this.border='20px solid #0f0';
this.backgroundColor='#00f';
}
DivB.prototype=new DivA();
window.onload=function(){
var div2=new DivB();
div2.display();
}
</script>
non utilizzando prototype.
Sono anche graditi links![]()
![]()


Rispondi quotando