06-Getter-Setter.html


Dosyayı İndir
<html>
<head>
	<script>
		class Rectangle{
		
			constructor(width=1,height=1){
				this._width=width;
				this._height=height;
			}
			
			
			set width (width) { 
				if(width<0){
					this._width=-width; 
				}else{
					this._width=width; 
				}
				
			}
			get width() { 
				return this._width;
			}
			set height (height) { 
				if(height<0){
					  throw new Error('Yükseklik eksi olamaz '+height);
				}
				this._height=height; 
			}
			get height() { 
				return this._height;
			}
			
			get area(){
				return this.width*this.height;
			}
			
			get perimeter(){
				return 2*(this.width+this.height);
			}
		}
		
		var rectangle=new Rectangle();
		rectangle.width=3;
		rectangle.height=-4;
		console.log("Genişlik: "+rectangle.width);
		console.log("Yükseklik: "+rectangle.height);
		console.log("Alan: "+rectangle.area);
		console.log("Çevre: "+rectangle.perimeter);
		
		
	</script>
</head>
<body>
	<h1> Edin/Ata </h1>
</body>
</html>

				
Dosyayı İndir

Bu Sayfayı Paylaş:




Bu Sayfayı Paylaş:

İletişim Bilgileri

Takip Et

Her Hakkı Saklıdır. Bu sitede yayınlanan tüm bilgi ve fikirlerin kullanımından fibiler.com sorumlu değildir. Bu sitede üretilmiş , derlenmiş içerikleri, fibiler.com'u kaynak göstermek koşuluyla kendi sitenizde kullanılabilirsiniz. Ancak telif hakkı olan içeriklerin hakları sahiplerine aittir