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
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
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 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 setApiVersion(constructor) { | |
constructor.api = '0.0.1'; | |
} | |
@setApiVersion | |
class Wizard {} | |
console.log(Wizard); // { [Function: Wizard] api: '0.0.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
function log(prefix) { | |
return target => { | |
console.log(`${prefix} - ${target}`); | |
} | |
} | |
@log('Awesome') | |
class Foo {} | |
// Awesome - function Foo() { |
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 log(target) { | |
console.log(target); | |
} | |
@log | |
class Foo {} | |
// [Function: Foo] |
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
interface Logger { | |
warn(message: string): void; | |
} | |
class ConsoleLogger implements Logger { | |
warn(message: string): void { | |
console.warn(message); | |
} | |
} |
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
class NullLogger implements Logger { | |
warn(message: string): void { | |
} | |
} | |
class LoggerFactory { | |
factory(env: string): Logger { | |
if (env === 'development') { | |
return new ConsoleLogger(); | |
} |
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
<?php | |
function premiumUsers($users) | |
{ | |
return array_filter($users, function ($user) { | |
return $user->type === USER_TYPE_PREMIUM; | |
}); | |
} |