Skip to content

Instantly share code, notes, and snippets.

View Augustpi's full-sized avatar
🖖
Hi there

Avni Onur Pehlivan Augustpi

🖖
Hi there
View GitHub Profile
@Augustpi
Augustpi / map-convert-plain-object.js
Created March 29, 2021 13:24
Medium, map example -4
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
@Augustpi
Augustpi / map-iterable.js
Last active March 29, 2021 13:24
Medium, Array, Map, Set, WeakMap example 3
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
}
@Augustpi
Augustpi / map-chaining-example.js
Created March 29, 2021 12:50
Medium, Array, Map, Set, WeakMap example 2
let map = new Map();
map.set('1', 'str1')
.set(1, 'num1')
.set(true, 'bool1');
console.log(map.size) // 3
@Augustpi
Augustpi / map-example-1.js
Last active March 29, 2021 12:17
Medium, Array, Map, Set, WeakMap example 1
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.
@Augustpi
Augustpi / immutible-primitive-example-1.js
Created March 29, 2021 11:40
This example will help you understand that primitive values are immutable.
// 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");
@Augustpi
Augustpi / functions-singleton-example-1.js
Last active March 27, 2021 16:40
Medium - functions
export let store = (function () {
let instance;
function init() {
// Private methods and variables
let _counter = 0;
// Private methods
function _getCounter() {
@Augustpi
Augustpi / proxy-validation-example-4.js
Created March 26, 2021 18:17
Medium - JavaScript Proxy kullanımı Örnek 4
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')
}
}
@Augustpi
Augustpi / proxy-check-property-example-3.js
Created March 26, 2021 18:15
Medium - Javascript Proxy kullanımı örnek 3
let handler = {
get: function (target, name) {
return name in target
? target[name]
: 'key, obje içinde bulunmuyor';
},
};
let obj = {
code: "code",
@Augustpi
Augustpi / proxy-example-2.js
Created March 26, 2021 18:11
medium - javascript proxy kullanımı örnek 2
function onChangeFunction() {
console.log('onChangeFunction');
}
var handler = {
getOwnPropertyDescriptor(target, prop) {
console.log("getOwnPropertyDescriptor");
return Object.getOwnPropertyDescriptor(target, prop);
},
@Augustpi
Augustpi / example-1.js
Created March 26, 2021 18:07
medium - proxy
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