This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let map = new Map(); | |
| map.set('domates', 1); | |
| map.set('biber', 2); | |
| let obj = Object.fromEntries(map.entries()); // Obje'ye çevirelim | |
| // obj = { domates: 1, biber: 2} | |
| console.log(obj.domates); // 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let myMapObj = new Map([ | |
| ['domates', 500], | |
| ['biber', 350], | |
| ['patlıcan', 50] | |
| ]); | |
| // keys (mapObj), Tüm anahtarları alalım | |
| for (let key of myMapObj.keys()) { | |
| console.log(key); // domates, biber, patlıcan | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let map = new Map(); | |
| map.set('1', 'str1') | |
| .set(1, 'num1') | |
| .set(true, 'bool1'); | |
| console.log(map.size) // 3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let map = new Map(); | |
| let keyFunc = function () {}; | |
| let keyObj = {}; | |
| map.set('1', 'str1'); // string anahtar | |
| map.set(1, 'num1'); // numeric anahtar | |
| map.set(true, 'bool1'); // boolean anahtar ile | |
| map.set(keyFunc, 'function') // key bir fonksiyon da olabilir | |
| map.set(keyObj, true) // key bir obje, değeri ise boolean tutabilir. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // String methodları ile bir string değişken değiştirilemez | |
| var bar = "baz"; | |
| console.log(bar); // baz | |
| bar.toUpperCase(); | |
| console.log(bar); // baz | |
| // Array methodları ile diziyi değiştirelim | |
| var foo = []; | |
| console.log(foo); // [] | |
| foo.push("plugh"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export let store = (function () { | |
| let instance; | |
| function init() { | |
| // Private methods and variables | |
| let _counter = 0; | |
| // Private methods | |
| function _getCounter() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let validator = { | |
| set: function(obj, prop, value) { | |
| if (prop === 'age') { | |
| if(!Number.isInteger(value)) { | |
| throw new Error('Yaş için rakam girmelisiniz') | |
| } | |
| if (value > 110) { | |
| throw new RangeError('Bu değer beklenenden yüksek') | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let handler = { | |
| get: function (target, name) { | |
| return name in target | |
| ? target[name] | |
| : 'key, obje içinde bulunmuyor'; | |
| }, | |
| }; | |
| let obj = { | |
| code: "code", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function onChangeFunction() { | |
| console.log('onChangeFunction'); | |
| } | |
| var handler = { | |
| getOwnPropertyDescriptor(target, prop) { | |
| console.log("getOwnPropertyDescriptor"); | |
| return Object.getOwnPropertyDescriptor(target, prop); | |
| }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let target = {}; | |
| let proxy = new Proxy(target, {}); // boş bir handler objesi ile! | |
| proxy.test = 5; | |
| console.log(target); // {test: 5} | |
| console.log(proxy); // Proxy {test: 5} | |
| for (let key in proxy) console.log(key); | |
| // test |