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 setApiVersion(constructor) { | |
return class extends constructor { | |
version = '0.0.1'; | |
} | |
} | |
@setApiVersion | |
class Wizard { | |
} |
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 logProperty(target: any, key: string) { | |
const newKey = `_${key}`; | |
Object.defineProperty(target, key, { | |
get() { | |
console.log(`Get: ${key} => ${this[newKey]}`); | |
return this[newKey]; | |
}, | |
set(newVal) { | |
console.log(`Set: ${key} => ${newVal}`); |
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 analyze(target: any, key: string) { | |
console.log(target, key); | |
} | |
class Task { | |
@analyze | |
public title: string; | |
constructor(title: string) { | |
this.title = title; |
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
const arr1 = ['a', 'b', 'c', [1, 2, 3]]; | |
const arr1Flatted = arr1.flat(); | |
// ["a", "b", "c", 1, 2, 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
const arr1 = ['a', ['b', ['c']], 1, [2, [3, [4, [5]]]]]; | |
const arr1Flatted1 = arr1.flat(); | |
// ["a", "b", Array(1), 1, 2, Array(2)] | |
const arr1Flatted2 = arr1.flat(2); | |
// ["a", "b", "c", 1, 2, 3, Array(2)] | |
const arr1FlattedInfinity = arr1.flat(Infinity); | |
// ["a", "b", "c", 1, 2, 3, 4, 5] |
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
const arr1 = ['a', 'b', , , , ['c', , 1, null, undefined, '', 0]]; | |
const arr1Flatted = arr1.flat(); | |
// ["a", "b", "c", 1, null, undefined, "", 0] |
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
const arr1 = [1, 2, 3, 4]; | |
const arr1FlattedMultipliedByTwo = arr1.flatMap(v => [ v * 2 ]); | |
// arr1FlattedMultipliedByTwo |
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
const entries = [ ['name', 'Marcos'], ['site', 'omark.dev'], ['twitter', '@omarkdev'] ]; | |
Object.fromEntries(entries); | |
// {name: "Marcos", site: "omark.dev", twitter: "@omarkdev"} |
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
const message = ' Hello world! '; | |
message.trimEnd(); | |
// " Hello world!" | |
message.trimStart(); | |
// "Hello world! " |
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
const symbol1 = Symbol('Awesome'); | |
symbol1.toString(); | |
// "Symbol(Awesome)" |