Class Örnekleri
<script>
class Ev {
/*constructor() {
}*/
constructor(Renk, En, Boy) {
this.Renk = Renk ?? 'black';
this.En = En ?? 50;
this.Boy = Boy ?? 50;
}
evCiz(Kaplama, Genislik, Yukseklik) {
this.Renk = Kaplama ?? this.Renk;
this.En = Yukseklik ?? this.En;
this.Boy = Genislik ?? this.Boy;
let Ciz = `<div style="background-color: ${this.Renk}; height:${this.En}px; width:${this.Boy}px; margin:50px; display:inline-block;"></div>`;
return Ciz;
}
}
const YeniEv = new Ev();
document.write(YeniEv.evCiz()); //constructor ayarlarına göre çizer
for(i=0; i<100; i++) {
document.write(YeniEv.evCiz('yellow', 100, 100));
}
</script>
class Ev {
/*constructor() {
}*/
constructor(Renk, En, Boy) {
this.Renk = Renk ?? 'black';
this.En = En ?? 50;
this.Boy = Boy ?? 50;
}
evCiz(Kaplama, Genislik, Yukseklik) {
this.Renk = Kaplama ?? this.Renk;
this.En = Yukseklik ?? this.En;
this.Boy = Genislik ?? this.Boy;
let Ciz = `<div style="background-color: ${this.Renk}; height:${this.En}px; width:${this.Boy}px; margin:50px; display:inline-block;"></div>`;
return Ciz;
}
}
const YeniEv = new Ev();
document.write(YeniEv.evCiz()); //constructor ayarlarına göre çizer
for(i=0; i<100; i++) {
document.write(YeniEv.evCiz('yellow', 100, 100));
}
</script>
<script>
class Ev{
constructor(Renk,Boy,En){
this.renk = Renk ?? "#000000";
this.boy = Boy ?? 50;
this.en = En ?? 50;
}
evCiz(rengi = this.renk,boyu = this.boy ,eni = this.en){
let cizilecekEv = document.createElement("div");
cizilecekEv.style.backgroundColor = rengi;
cizilecekEv.style.width = boyu+ 'px';
cizilecekEv.style.height = eni+ 'px';
cizilecekEv.style.margin = "50px";
cizilecekEv.style.display = "inline-block";
return cizilecekEv;
}
}
const yeniEv = new Ev('#00ffff',100,100)
const yeniEv2 = new Ev()
document.getElementsByTagName("body")[0].append(yeniEv.evCiz('#ff00ff',50,50));
document.getElementsByTagName("body")[0].append(yeniEv2.evCiz());
for(i=0;i<100;i++){
document.getElementsByTagName("body")[0].append(yeniEv.evCiz());
}
</script>
class Ev{
constructor(Renk,Boy,En){
this.renk = Renk ?? "#000000";
this.boy = Boy ?? 50;
this.en = En ?? 50;
}
evCiz(rengi = this.renk,boyu = this.boy ,eni = this.en){
let cizilecekEv = document.createElement("div");
cizilecekEv.style.backgroundColor = rengi;
cizilecekEv.style.width = boyu+ 'px';
cizilecekEv.style.height = eni+ 'px';
cizilecekEv.style.margin = "50px";
cizilecekEv.style.display = "inline-block";
return cizilecekEv;
}
}
const yeniEv = new Ev('#00ffff',100,100)
const yeniEv2 = new Ev()
document.getElementsByTagName("body")[0].append(yeniEv.evCiz('#ff00ff',50,50));
document.getElementsByTagName("body")[0].append(yeniEv2.evCiz());
for(i=0;i<100;i++){
document.getElementsByTagName("body")[0].append(yeniEv.evCiz());
}
</script>
Yorumunuzu Ekleyin