Skip to content

Instantly share code, notes, and snippets.

View YozhEzhi's full-sized avatar

Alexandr Zhidovlenko YozhEzhi

  • Sportmaster Lab
  • Saint-Petersburg, Russia
View GitHub Profile
// ================================================================
// Apply: Get max item
// ================================================================
var arr = [1, 2, 50, 20, 38, 88];
function getMax(arr) {
return Math.max.apply(null, arr); // ES6: Math.max(...arr)
};
console.log(arr.getMax(arr)); // 88;

// ================================================================ // MVC (Model-View-Controller) // https://ru.wikipedia.org/wiki/Model-View-Controller // https://upload.wikimedia.org/wikipedia/commons/f/fd/MVC-Process.png // ================================================================ /** Концепция MVC позволяет разделить данные (модель), представление и обработку действий (производимую контроллером) пользователя на три отдельных компонента:

  • Модель:
/*
* ================================================================
* Creational patterns
* ================================================================
*/
/**
* Generating objects with Object.create().
* Object.create creates prototype chain for object extending.
* https://jsbin.com/resixu/19/edit?html,js,console
*/
/**
* Factory Functions.
*/
/*
* ES6 class vs Factory function:
* With class -- Be wary
*/
class Dog {
constructor() {
this.sound = 'woof';
@YozhEzhi
YozhEzhi / remarks.md
Last active July 21, 2020 20:27
[Заметки] JS

В JavaScript используется интересный подход к работе с необъявленными переменными.

Обращение к такой переменной создаёт новую переменную в глобальном объекте. В случае с браузерами, глобальным объектом является window. Рассмотрим такую конструкцию:

function foo(arg) {
    bar = "some text";
}
Array.apply(null, {length: 20}).map(Number.call, Number)
// -> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
// Данный код будет работать некорректно без точек с запятыми:
function getN() {
return 2
}
var a = getN()
(function(){
return 6
})()
@YozhEzhi
YozhEzhi / loop.js
Last active May 19, 2020 20:49
Remove files by name.
const fs = require('fs');
const path = require('path');
const updateFile = filename => {
const search = "postcss 'src/**/*.css' -d ./build --base src/";
const shouldBe =
"postcss 'src/**/*.css' -d ./build --base src/ --config '../../postcss.config.js'";
fs.readFile(filename, 'utf8', (err, data) => {
if (err) {
# Settings:
alias conf:update=". ~/.zprofile"
alias config:update=". ~/.zprofile"
alias conf:bash="cd ~ && subl .zprofile"
alias config:bash="cd ~ && subl .zprofile"
alias conf:hosts="cd ~/../../private/etc && subl hosts"
alias config:hosts="cd ~/../../private/etc && subl hosts"
# Locations:
alias desk="cd ~/Desktop"
@YozhEzhi
YozhEzhi / currying.md
Created July 9, 2018 20:51
Каррирование.

Каррирование - это способ конструирования функций, позволяющий частичное применение аргументов функции. Т.е. мы можем передать все аргументы, ожидаемые функцией и получить результат, или же передать часть этих аргументов и получить обратно функцию, которая ожидает остальные аргументы.

// Обычная функция приветствия:
var greet = function(greeting, name) {
  console.log(greeting + ", " + name);
};
greet("Hello", "Heidi"); // "Hello, Heidi"