Unverified Kaydet (Commit) fbf71eca authored tarafından Mert Can Bilgiç's avatar Mert Can Bilgiç Kaydeden (comit) GitHub

Update README.md

Nesneler ve veri yapıları çevrildi
üst 6cd08cb2
...@@ -901,105 +901,104 @@ inventoryTracker('apples', req, 'www.inventory-awesome.io'); ...@@ -901,105 +901,104 @@ inventoryTracker('apples', req, 'www.inventory-awesome.io');
``` ```
**[⬆ en başa dön](#içindekiler)** **[⬆ en başa dön](#içindekiler)**
## **Objects and Data Structures** ## **Nesneler ve Veri Yapıları**
### Use getters and setters ### Setter ve Getter kullanın
Using getters and setters to access data on objects could be better than simply Nesnelerdeki verilere erişmek için Setter ve Getter kullanmak sadece bir nesnedeki
looking for a property on an object. "Why?" you might ask. Well, here's an özellikleri aramaktan daha iyi olabilir. "Neden?" diye soracaksınız. Peki, işte burada
unorganized list of reasons why: sebeplerinin bir listesi var:
* When you want to do more beyond getting an object property, you don't have * Bir nesne özelliğini elde etmekten daha fazla şey yapmak istediğinizde kod tabanınızdaki
to look up and change every accessor in your codebase. her erişimciyi aramanız ve değiştirmeniz gerekmez.
* Makes adding validation simple when doing a `set`. * `set` işlemi yaparken doğrulama eklemeyi kolaylaştırır.
* Encapsulates the internal representation. * İç temsili kapsüller.
* Easy to add logging and error handling when getting and setting. * Set ve Get işlemlerini gerçekleştirirken kayıt tutmayı (log) ve hata yakalamayı eklemek kolaydır.
* You can lazy load your object's properties, let's say getting it from a * Mesela nesnenizin özelliklerini sunucudan alırken Lazy Load kullanabilirsiniz.
server.
**Kötü:** **Kötü:**
```javascript ```javascript
function makeBankAccount() { function bankaHesabiOlustur() {
// ... // ...
return { return {
balance: 0, bakiye: 0,
// ... // ...
}; };
} }
const account = makeBankAccount(); const hesap = bankaHesabiOlustur();
account.balance = 100; hesap.bakiye = 100;
``` ```
**İyi:** **İyi:**
```javascript ```javascript
function makeBankAccount() { function bankaHesabiOlustur() {
// this one is private // bu private
let balance = 0; let bakiye = 0;
// a "getter", made public via the returned object below //Getter aşağıda döndürülen nesne aracılığıyla public hale getirildi
function getBalance() { function getBakiye() {
return balance; return bakiye;
} }
// a "setter", made public via the returned object below // Setter aşağıda döndürülen nesne aracılığıyla public hale getirildi
function setBalance(amount) { function setBakiye(deger) {
// ... validate before updating the balance // ... bakiyeyi güncellemeden önce onaylar
balance = amount; bakiye = deger;
} }
return { return {
// ... // ...
getBalance, getBakiye,
setBalance, setBakiye,
}; };
} }
const account = makeBankAccount(); const hesap = bankaHesabiOlustur();
account.setBalance(100); hesap.setBakiye(100);
``` ```
**[⬆ en başa dön](#içindekiler)** **[⬆ en başa dön](#içindekiler)**
### Make objects have private members ### Nesnelerin private üyelere sahip olmasını sağlayın.
This can be accomplished through closures (for ES5 and below). Bu, kapamalarla(closures) gerçekleştirilebilir. (ES5 ve altı için).
**Kötü:** **Kötü:**
```javascript ```javascript
const Employee = function(name) { const Calisan = function(isim) {
this.name = name; this.isim = isim;
}; };
Employee.prototype.getName = function getName() { Calisan.prototype.getIsim = function getIsim() {
return this.name; return this.isim;
}; };
const employee = new Employee('John Doe'); const calisan = new calisan('John Doe');
console.log(`Employee name: ${employee.getName()}`); // Employee name: John Doe console.log(`Calisanin ismi: ${calisan.getIsim()}`); // Calisanin ismi: John Doe
delete employee.name; delete calisan.isim;
console.log(`Employee name: ${employee.getName()}`); // Employee name: undefined console.log(`Calisanin ismi: ${calisan.getIsim()}`); // Calisanin ismi: undefined
``` ```
**İyi:** **İyi:**
```javascript ```javascript
function makeEmployee(name) { function calisanOlustur(isim) {
return { return {
getName() { getIsim() {
return name; return isim;
}, },
}; };
} }
const employee = makeEmployee('John Doe'); const calisan = calisanOlustur('John Doe');
console.log(`Employee name: ${employee.getName()}`); // Employee name: John Doe console.log(`Calisanin ismi: ${calisan.getIsim()}`); // Calisanin ismi: John Doe
delete employee.name; delete calisan.isim;
console.log(`Employee name: ${employee.getName()}`); // Employee name: John Doe console.log(`Calisanin ismi: ${calisan.getIsim()}`); // Calisanin ismi: John Doe
``` ```
**[⬆ en başa dön](#içindekiler)** **[⬆ en başa dön](#içindekiler)**
## **Classes** ## **Sınıflar**
### Prefer ES2015/ES6 classes over ES5 plain functions ### Prefer ES2015/ES6 classes over ES5 plain functions
It's very difficult to get readable class inheritance, construction, and method It's very difficult to get readable class inheritance, construction, and method
definitions for classical ES5 classes. If you need inheritance (and be aware definitions for classical ES5 classes. If you need inheritance (and be aware
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment