.gdpr{position: fixed; top: 0; bottom: 0; left: 0; right: 0; background: rgba(0, 0, 0, 0.7);color: #333;z-index:9999999;line-height:1.3;height: 100vh;width: 100vw} .gdpr_w{padding: 2rem;background: #fff;max-width: 700px;width: 95%;margin: 5% auto;text-align: center;position:fixed;left: 0;right: 0;margin:10% auto;} .gdpr_t{margin-bottom:15px;} .gdpr_t h3{font-size: 30px;margin:0px 0 10px 0;} .gdpr_t p{font-size: 16px;line-height: 1.45;margin:0;} .gdpr_x {position: absolute; right: 24px; top: 16px; cursor:pointer;} .gdpr_yn{margin-top:10px;} .gdpr_yn form{display: inline;} .gdpr_yn button{background: #37474F;border: none;color: #fff;padding: 8px 30px;font-size: 13px;margin: 0 3px;} .gdpr_yn .gdpr_n{background: #fff;color: #222;border: 1px solid #999;} amp-consent{margin-left: 10px;top: 2px;width: auto;background: transparent;} .gdpr_fmi{ width:100%; font-size: 15px; line-height: 1.45; margin: 0; } #footer .gdpr_fmi span, .gdpr_fmi span { display: inline-block; } #footer .gdpr_fmi a{ color: #005be2; } @media(max-width:768px){ .gdpr_w{width: 85%;margin:0 auto;padding:1.5rem;} } @media(max-width:700px){ .gdpr_w{margin:0 auto; width: 85%;} } .gdpr_fmi a:before{ display:none; } .gdpr_w{width:100%;} .f-w-f2 { padding: 50px 0px; } footer amp-consent.amp-active { z-index:9999; display: initial; position: inherit; height:20px; width:100%; } body[class*="amp-iso-country-"] .amp-active{ display: contents; } #post-consent-ui { position: fixed; z-index: 9999; left: 45%; margin-top: 10px; top: 0; } @font-face { font-family: Poppins;font-display: optional;font-style: normal;font-weight: 400;src: local('Poppins Regular '), local('Poppins-Regular'), url(https://fonts.gstatic.com/s/poppins/v13/pxiEyp8kv8JHgFVrFJDUc1NECPY.ttf);}@font-face { font-family: Poppins;font-display: optional;font-style: normal;font-weight: 500;src: local('Poppins Medium '), local('Poppins-Medium'), url(https://fonts.gstatic.com/s/poppins/v13/pxiByp8kv8JHgFVrLGT9V1tvFP-KUEg.ttf);}@font-face { font-family: Poppins;font-display: optional;font-style: normal;font-weight: 700;src: local('Poppins Bold '), local('Poppins-Bold'), url(https://fonts.gstatic.com/s/poppins/v13/pxiByp8kv8JHgFVrLCz7V1tvFP-KUEg.ttf);}a.heateor_sss_amp{padding:0 4px}div.heateor_sss_horizontal_sharing a amp-img{display:inline-block}.heateor_sss_amp_instagram img{background-color:#624E47}.heateor_sss_amp_yummly img{background-color:#E16120}.heateor_sss_amp_youtube img{background-color:#ff0000}.heateor_sss_amp_buffer img{background-color:#000}.heateor_sss_amp_delicious img{background-color:#53BEEE}.heateor_sss_amp_facebook img{background-color:#3C589A}.heateor_sss_amp_digg img{background-color:#006094}.heateor_sss_amp_email img{background-color:#649A3F}.heateor_sss_amp_float_it img{background-color:#53BEEE}.heateor_sss_amp_linkedin img{background-color:#0077B5}.heateor_sss_amp_pinterest img{background-color:#CC2329}.heateor_sss_amp_print img{background-color:#FD6500}.heateor_sss_amp_reddit img{background-color:#FF5700}.heateor_sss_amp_stocktwits img{background-color:#40576F}.heateor_sss_amp_mewe img{background-color:#007da1}.heateor_sss_amp_mix img{background-color:#ff8226}.heateor_sss_amp_tumblr img{background-color:#29435D}.heateor_sss_amp_twitter img{background-color:#55acee}.heateor_sss_amp_vkontakte img{background-color:#5E84AC}.heateor_sss_amp_yahoo img{background-color:#8F03CC}.heateor_sss_amp_xing img{background-color:#00797D}.heateor_sss_amp_instagram img{background-color:#527FA4}.heateor_sss_amp_whatsapp img{background-color:#55EB4C}.heateor_sss_amp_aim img{background-color:#10ff00}.heateor_sss_amp_amazon_wish_list img{background-color:#ffe000}.heateor_sss_amp_aol_mail img{background-color:#2A2A2A}.heateor_sss_amp_app_net img{background-color:#5D5D5D}.heateor_sss_amp_baidu img{background-color:#2319DC}.heateor_sss_amp_balatarin img{background-color:#fff}.heateor_sss_amp_bibsonomy img{background-color:#000}.heateor_sss_amp_bitty_browser img{background-color:#EFEFEF}.heateor_sss_amp_blinklist img{background-color:#3D3C3B}.heateor_sss_amp_blogger_post img{background-color:#FDA352}.heateor_sss_amp_blogmarks img{background-color:#535353}.heateor_sss_amp_bookmarks_fr img{background-color:#E8EAD4}.heateor_sss_amp_box_net img{background-color:#1A74B0}.heateor_sss_amp_buddymarks img{background-color:#ffd400}.heateor_sss_amp_care2_news img{background-color:#6EB43F}.heateor_sss_amp_citeulike img{background-color:#2781CD}.heateor_sss_amp_comment img{background-color:#444}.heateor_sss_amp_diary_ru img{background-color:#E8D8C6}.heateor_sss_amp_diaspora img{background-color:#2E3436}.heateor_sss_amp_dihitt img{background-color:#FF6300}.heateor_sss_amp_diigo img{background-color:#4A8BCA}.heateor_sss_amp_douban img{background-color:#497700}.heateor_sss_amp_draugiem img{background-color:#ffad66}.heateor_sss_amp_dzone img{background-color:#fff088}.heateor_sss_amp_evernote img{background-color:#8BE056}.heateor_sss_amp_facebook_messenger img{background-color:#0084FF}.heateor_sss_amp_fark img{background-color:#555}.heateor_sss_amp_fintel img{background-color:#087515}.heateor_sss_amp_flipboard img{background-color:#CC0000}.heateor_sss_amp_folkd img{background-color:#0F70B2}.heateor_sss_amp_google_classroom img{background-color:#FFC112}.heateor_sss_amp_google_bookmarks img{background-color:#CB0909}.heateor_sss_amp_google_gmail img{background-color:#E5E5E5}.heateor_sss_amp_hacker_news img{background-color:#F60}.heateor_sss_amp_hatena img{background-color:#00A6DB}.heateor_sss_amp_instapaper img{background-color:#EDEDED}.heateor_sss_amp_jamespot img{background-color:#FF9E2C}.heateor_sss_amp_kakao img{background-color:#FCB700}.heateor_sss_amp_kik img{background-color:#2A2A2A}.heateor_sss_amp_kindle_it img{background-color:#2A2A2A}.heateor_sss_amp_known img{background-color:#fff101}.heateor_sss_amp_line img{background-color:#00C300}.heateor_sss_amp_livejournal img{background-color:#EDEDED}.heateor_sss_amp_mail_ru img{background-color:#356FAC}.heateor_sss_amp_mendeley img{background-color:#A70805}.heateor_sss_amp_meneame img{background-color:#FF7D12}.heateor_sss_amp_mixi img{background-color:#EDEDED}.heateor_sss_amp_myspace img{background-color:#2A2A2A}.heateor_sss_amp_netlog img{background-color:#2A2A2A}.heateor_sss_amp_netvouz img{background-color:#c0ff00}.heateor_sss_amp_newsvine img{background-color:#055D00}.heateor_sss_amp_nujij img{background-color:#D40000}.heateor_sss_amp_odnoklassniki img{background-color:#F2720C}.heateor_sss_amp_oknotizie img{background-color:#fdff88}.heateor_sss_amp_outlook_com img{background-color:#0072C6}.heateor_sss_amp_papaly img{background-color:#3AC0F6}.heateor_sss_amp_pinboard img{background-color:#1341DE}.heateor_sss_amp_plurk img{background-color:#CF682F}.heateor_sss_amp_pocket img{background-color:#f0f0f0}.heateor_sss_amp_polyvore img{background-color:#2A2A2A}.heateor_sss_amp_printfriendly img{background-color:#61D1D5}.heateor_sss_amp_protopage_bookmarks img{background-color:#413FFF}.heateor_sss_amp_pusha img{background-color:#0072B8}.heateor_sss_amp_qzone img{background-color:#2B82D9}.heateor_sss_amp_refind img{background-color:#1492ef}.heateor_sss_amp_rediff_mypage img{background-color:#D20000}.heateor_sss_amp_renren img{background-color:#005EAC}.heateor_sss_amp_segnalo img{background-color:#fdff88}.heateor_sss_amp_sina_weibo img{background-color:#ff0}.heateor_sss_amp_sitejot img{background-color:#ffc800}.heateor_sss_amp_skype img{background-color:#00AFF0}.heateor_sss_amp_sms img{background-color:#6ebe45}.heateor_sss_amp_slashdot img{background-color:#004242}.heateor_sss_amp_stumpedia img{background-color:#EDEDED}.heateor_sss_amp_svejo img{background-color:#fa7aa3}.heateor_sss_amp_symbaloo_feeds img{background-color:#6DA8F7}.heateor_sss_amp_telegram img{background-color:#3DA5f1}.heateor_sss_amp_trello img{background-color:#1189CE}.heateor_sss_amp_tuenti img{background-color:#0075C9}.heateor_sss_amp_twiddla img{background-color:#EDEDED}.heateor_sss_amp_typepad_post img{background-color:#2A2A2A}.heateor_sss_amp_viadeo img{background-color:#2A2A2A}.heateor_sss_amp_viber img{background-color:#8B628F}.heateor_sss_amp_wanelo img{background-color:#fff}.heateor_sss_amp_webnews img{background-color:#CC2512}.heateor_sss_amp_wordpress img{background-color:#464646}.heateor_sss_amp_wykop img{background-color:#367DA9}.heateor_sss_amp_yahoo_mail img{background-color:#400090}.heateor_sss_amp_yahoo_messenger img{background-color:#400090}.heateor_sss_amp_yoolink img{background-color:#A2C538}.heateor_sss_amp_youmob img{background-color:#3B599D}.heateor_sss_amp_gentlereader img{background-color:#46aecf}.heateor_sss_amp_threema img{background-color:#2A2A2A}.heateor_sss_vertical_sharing{position:fixed;left:11px;z-index:99999}.heateor-total-share-count .sss_share_count{color:#666;font-size:23px}.heateor-total-share-count .sss_share_lbl{color:#666}.amp-wp-enforced-sizes img[alt="Pinterest"]{background:#cc2329}.amp-wp-enforced-sizes img[alt="Viber"]{background:#8b628f}.amp-wp-enforced-sizes img[alt="Print"]{background:#fd6500}.amp-wp-enforced-sizes img[alt="Threema"]{background:#2a2a2a}.amp-wp-article-content .heateor_sss_vertical_sharing{left:5px}.amp-wp-article-content amp-img[alt="Pinterest"]{left:4px}.amp-wp-enforced-sizes img[alt="MySpace"]{background:#2a2a2a} amp-web-push-widget button.amp-subscribe { display: inline-flex; align-items: center; border-radius: 5px; border: 0; box-sizing: border-box; margin: 0; padding: 10px 15px; cursor: pointer; outline: none; font-size: 15px; font-weight: 500; background: #4A90E2; margin-top: 7px; color: white; box-shadow: 0 1px 1px 0 rgba(0, 0, 0, 0.5); -webkit-tap-highlight-color: rgba(0, 0, 0, 0); } a.heateor_sss_amp{padding:0 4px;}div.heateor_sss_horizontal_sharing a amp-img{display:inline-block;}.heateor_sss_amp_gab img{background-color:#25CC80}.heateor_sss_amp_parler img{background-color:#892E5E}.heateor_sss_amp_gettr img{background-color:#E50000}.heateor_sss_amp_instagram img{background-color:#624E47}.heateor_sss_amp_yummly img{background-color:#E16120}.heateor_sss_amp_youtube img{background-color:#ff0000}.heateor_sss_amp_teams img{background-color:#5059c9}.heateor_sss_amp_google_translate img{background-color:#528ff5}.heateor_sss_amp_x img{background-color:#2a2a2a}.heateor_sss_amp_rutube img{background-color:#14191f}.heateor_sss_amp_buffer img{background-color:#000}.heateor_sss_amp_delicious img{background-color:#53BEEE}.heateor_sss_amp_rss img{background-color:#e3702d}.heateor_sss_amp_facebook img{background-color:#0765FE}.heateor_sss_amp_perplexity img{background-color:#165962}.heateor_sss_amp_claude img{background-color:#D97757}.heateor_sss_amp_google_ai img{background-color:#000}.heateor_sss_amp_grok img{background-color:#000}.heateor_sss_amp_chatgpt img{background-color:#000}.heateor_sss_amp_digg img{background-color:#006094}.heateor_sss_amp_email img{background-color:#649A3F}.heateor_sss_amp_float_it img{background-color:#53BEEE}.heateor_sss_amp_linkedin img{background-color:#0077B5}.heateor_sss_amp_pinterest img{background-color:#CC2329}.heateor_sss_amp_print img{background-color:#FD6500}.heateor_sss_amp_reddit img{background-color:#FF5700}.heateor_sss_amp_mastodon img{background-color:#6364FF}.heateor_sss_amp_stocktwits img{background-color: #40576F}.heateor_sss_amp_mewe img{background-color:#007da1}.heateor_sss_amp_mix img{background-color:#ff8226}.heateor_sss_amp_tumblr img{background-color:#29435D}.heateor_sss_amp_twitter img{background-color:#55acee}.heateor_sss_amp_vkontakte img{background-color:#0077FF}.heateor_sss_amp_yahoo img{background-color:#8F03CC}.heateor_sss_amp_xing img{background-color:#00797D}.heateor_sss_amp_instagram img{background-color:#527FA4}.heateor_sss_amp_whatsapp img{background-color:#55EB4C}.heateor_sss_amp_aim img{background-color: #10ff00}.heateor_sss_amp_amazon_wish_list img{background-color: #ffe000}.heateor_sss_amp_aol_mail img{background-color: #2A2A2A}.heateor_sss_amp_app_net img{background-color: #5D5D5D}.heateor_sss_amp_balatarin img{background-color: #fff}.heateor_sss_amp_bibsonomy img{background-color: #000}.heateor_sss_amp_bitty_browser img{background-color: #EFEFEF}.heateor_sss_amp_blinklist img{background-color: #3D3C3B}.heateor_sss_amp_blogger_post img{background-color: #FDA352}.heateor_sss_amp_blogmarks img{background-color: #535353}.heateor_sss_amp_bookmarks_fr img{background-color: #E8EAD4}.heateor_sss_amp_box_net img{background-color: #1A74B0}.heateor_sss_amp_buddymarks img{background-color: #ffd400}.heateor_sss_amp_care2_news img{background-color: #6EB43F}.heateor_sss_amp_comment img{background-color: #444}.heateor_sss_amp_diary_ru img{background-color: #E8D8C6}.heateor_sss_amp_diaspora img{background-color: #2E3436}.heateor_sss_amp_dihitt img{background-color: #FF6300}.heateor_sss_amp_diigo img{background-color: #4A8BCA}.heateor_sss_amp_douban img{background-color: #497700}.heateor_sss_amp_draugiem img{background-color: #ffad66}.heateor_sss_amp_evernote img{background-color: #8BE056}.heateor_sss_amp_facebook_messenger img{background-color: #0084FF}.heateor_sss_amp_fark img{background-color: #555}.heateor_sss_amp_fintel img{background-color: #087515}.heateor_sss_amp_flipboard img{background-color: #CC0000}.heateor_sss_amp_folkd img{background-color: #0F70B2}.heateor_sss_amp_google_news img{background-color: #4285F4}.heateor_sss_amp_google_classroom img{background-color: #FFC112}.heateor_sss_amp_google_gmail img{background-color: #E5E5E5}.heateor_sss_amp_hacker_news img{background-color: #F60}.heateor_sss_amp_hatena img{background-color: #00A6DB}.heateor_sss_amp_instapaper img{background-color: #EDEDED}.heateor_sss_amp_jamespot img{background-color: #FF9E2C}.heateor_sss_amp_kakao img{background-color: #FCB700}.heateor_sss_amp_kik img{background-color: #2A2A2A}.heateor_sss_amp_kindle_it img{background-color: #2A2A2A}.heateor_sss_amp_known img{background-color: #fff101}.heateor_sss_amp_line img{background-color: #00C300}.heateor_sss_amp_livejournal img{background-color: #EDEDED}.heateor_sss_amp_mail_ru img{background-color: #356FAC}.heateor_sss_amp_mendeley img{background-color: #A70805}.heateor_sss_amp_meneame img{background-color: #FF7D12}.heateor_sss_amp_mixi img{background-color: #EDEDED}.heateor_sss_amp_myspace img{background-color: #2A2A2A}.heateor_sss_amp_netlog img{background-color: #2A2A2A}.heateor_sss_amp_netvouz img{background-color: #c0ff00}.heateor_sss_amp_newsvine img{background-color: #055D00}.heateor_sss_amp_nujij img{background-color: #D40000}.heateor_sss_amp_odnoklassniki img{background-color: #F2720C}.heateor_sss_amp_oknotizie img{background-color: #fdff88}.heateor_sss_amp_outlook_com img{background-color: #0072C6}.heateor_sss_amp_papaly img{background-color: #3AC0F6}.heateor_sss_amp_pinboard img{background-color: #1341DE}.heateor_sss_amp_plurk img{background-color: #CF682F}.heateor_sss_amp_pocket img{background-color: #ee4056}.heateor_sss_amp_polyvore img{background-color: #2A2A2A}.heateor_sss_amp_printfriendly img{background-color: #61D1D5}.heateor_sss_amp_protopage_bookmarks img{background-color: #413FFF}.heateor_sss_amp_pusha img{background-color: #0072B8}.heateor_sss_amp_qzone img{background-color: #2B82D9}.heateor_sss_amp_refind img{background-color: #1492ef}.heateor_sss_amp_rediff_mypage img{background-color: #D20000}.heateor_sss_amp_renren img{background-color: #005EAC}.heateor_sss_amp_segnalo img{background-color: #fdff88}.heateor_sss_amp_sina_weibo img{background-color: #ff0}.heateor_sss_amp_sitejot img{background-color: #ffc800}.heateor_sss_amp_skype img{background-color: #00AFF0}.heateor_sss_amp_sms img{background-color: #6ebe45}.heateor_sss_amp_slashdot img{background-color: #004242}.heateor_sss_amp_stumpedia img{background-color: #EDEDED}.heateor_sss_amp_svejo img{background-color: #fa7aa3}.heateor_sss_amp_symbaloo_feeds img{background-color: #6DA8F7}.heateor_sss_amp_telegram img{background-color: #3DA5f1}.heateor_sss_amp_trello img{background-color: #1189CE}.heateor_sss_amp_tuenti img{background-color: #0075C9}.heateor_sss_amp_twiddla img{background-color: #EDEDED}.heateor_sss_amp_typepad_post img{background-color: #2A2A2A}.heateor_sss_amp_viadeo img{background-color: #2A2A2A}.heateor_sss_amp_viber img{background-color: #8B628F}.heateor_sss_amp_wordpress img{background-color: #464646}.heateor_sss_amp_wykop img{background-color: #367DA9}.heateor_sss_amp_yahoo_mail img{background-color: #400090}.heateor_sss_amp_yahoo_messenger img{background-color: #400090}.heateor_sss_amp_youmob img{background-color: #3B599D}.heateor_sss_amp_gentlereader img{background-color: #46aecf}.heateor_sss_amp_threema img{background-color: #2A2A2A}.heateor_sss_amp_bluesky img{background-color:#0085ff}.heateor_sss_amp_threads img{background-color:#000}.heateor_sss_amp_raindrop img{background-color:#0b7ed0}.heateor_sss_amp_micro_blog img{background-color:#ff8800}.heateor_sss_amp amp-img{border-radius:999px;} .amp-logo amp-img{width:190px} .amp-menu input{display:none;}.amp-menu li.menu-item-has-children ul{display:none;}.amp-menu li{position:relative;display:block;}.amp-menu > li a{display:block;} /* Inline styles */ div.acss138d7{clear:both;}div.acssf5b84{--relposth-columns:3;--relposth-columns_m:2;--relposth-columns_t:2;}div.acssae964{aspect-ratio:1/1;background:transparent no-repeat scroll 0% 0%;height:150px;max-width:150px;}div.acss6bdea{color:#333333;font-family:Arial;font-size:12px;height:75px;}div.acsse3e3c{font-weight:bold;}amp-img.acss334b9{max-width:35px;} .icon-widgets:before {content: "\e1bd";}.icon-search:before {content: "\e8b6";}.icon-shopping-cart:after {content: "\e8cc";}
JS

Записка по JS, а именно ECMAScript 6.

1. Переменные let

if(true){
    var version1 = 'ES5';
}

if(true){
    let version2 = 'ES6';
}
console.log(version1); // ES5
console.log(version2); // Error

Пример с кнопками:

// Создадим 5 <button></button> в html
let buttons = document.querySelectorAll('button');
// При button.onclick всегда будет "5"
for(var i = 0; i < buttons.length; i++){
    var button = buttons[i];
    button.innerText = i;
    button.onclick = function (e) {
        console.log(i); 
    }
}
// При button.onclick будет 1,2,3,4,5
for(let i = 0; i < buttons.length; i++){
    var button = buttons[i];
    button.innerText = i;
    button.onclick = function (e) {
        console.log(i);
    }
}

2. Константы const

const PI = 3.14;
const PI = 3.15; // Ошибка

const MATH = {
    PI: 3.14
};

MATH.PI = 3.15; 

console.log(MATH); // 3.15

3. Оператор разворота Spread и Rest

let staticLanguages = ['C','C++','Java'];

let dynamicLanguages = ['PHP', 'JS', 'Ruby'];

let Languages = [...staticLanguages,'C#', ...dynamicLanguages, 'Python'];

// ["C", "C++", "Java", "C#", "PHP", "JS", "Ruby", "Python"]
console.log(Languages);

function add(x,y,z) {
    console.log(x+y+z);
}

let number = [1,2,3];

add(...number);// 6

4. Шаблонные строки

function f(name) {
    console.log("Hello " + name); // Hello bill
    console.log(`Hello ${name}`); // Hello bill
}
f('bill');

// Вывод с новой строки
function f1(to,from,subject,message) {
    console.log(`
        to: ${to}
        from: ${from}
        subject: ${subject}
        message: ${message}
    `);
}
f1('test@test.ru','test2@mail.ru','Hello','How are you?');
// to: test@test.ru
// from: test2@mail.ru
// subject: Hello
// message: How are you?

function f2(x,y) {
    console.log(`${x} + ${y} = ${x + y}`)
}

function f3(x,y) {
    console.log(`${x} + ${y} = ${parseInt(x) + parseInt(y)}`)
}

f2(5,7); // 5 + 7 = 12
f2('5','7'); // 5 + 7 = 57
f3('5','7'); // 5 + 7 = 12

function upperName(literals, value) {
    return literals[0]+value.toUpperCase();
}

let name = 'Bill';
console.log(upperName`Hello ${name}`); // Hello BILL

5. Параметры function

function greet1(greeting,name) {
    console.log(`${greeting} ${name}`)
}

greet1("Hi","Bill"); // Hi Bill
greet1("Hi"); // Hi undefined

function greet2(greeting = 'Hello', name = 'Friend') {
    console.log(`${greeting} ${name}`)
}

greet2("Hi","Bill"); // Hi Bill
greet2("Hi"); // Hi Friend

function sum(...values) {
    let sum = 0;
    /*
    values.forEach(function (value) {
        sum += value;
    });
    console.log(sum);
    */    // Тоже самое
    console.log(values.reduce(function (prevValue,currentValue) {
       return prevValue + currentValue
    }));
}

sum(4,3,2); // 9    

6. Циклы (for…of)

let browsers = ['Chrome', 'Firefox', 'Opera', 'Edge'];

// 0 1 2 3
for(let browser in browsers){
    console.log(browser);
}

// Chrome Firefox Opera Edge
for(let index in browsers){
    console.log(browsers[index]);
}

// Chrome Firefox Opera Edge
for(let browser of browsers){
    console.log(browser);
}

7. Объекты

let firstName = 'Bill';
let lastName = 'Geits';
let email = 'bill@mc.com';

let person1 = {
    firstName: firstName,
    lastName: lastName,
    email: email,
};

let person2 = {
    firstName,
    lastName,
    email,
    sayHello() {
        console.log(`Hi my name is ${this.firstName} ${this.lastName}`)
    }
};

console.log(person1); // {firstName: "Bill", lastName: "Geits", email: "bill@mc.com"}
console.log(person2); // {firstName: "Bill", lastName: "Geits", email: "bill@mc.com", sayHello: ƒ}
person2.sayHello(); // Hi my name is Bill Geits
console.log(person2.firstName); // Bill
console.log(person2['lastName']); // Geits

let property = 'firstName';
console.log(person2[property]); // person2['firstName'] // Bill

// Динамические свойства

let person3 = {
  [property]: 'Ivan',
};

console.log(person3.firstName); // Ivan

// Разновидности создания динамичных свойств
function createCar(property, value) {
    return{
        [property]: value,
        ['_'+ property]: value,
        [property.toUpperCase()]: value,
        ['get'+property](){
            return this[property];
        }
    }
}

console.log(createCar('vin','123')); // {vin: "123", _vin: "123", VIN: "123", getvin: ƒ}

let person4 = {
    firstName,
    lastName,
    email,
    sayHello() {
        console.log(`Hi my name is ${this.firstName} ${this.lastName}`)
    },
    get fullname(){
        return this.firstName + ' ' + this.lastName;
    },
    set _firstName(name){
        this.firstName = name;
    }
};

person4._firstName = 'Ivan';
console.log(person4.fullname); // Ivan Geits
console.log(person4); // {firstName: "Ivan", lastName: "Geits", email: "bill@mc.com", sayHello: ƒ}

8. Классы

class Task {

    /*
    В ES6 нельзя:
    let title;
    static let count = 0;
    */
    constructor(title = Task.getDefaultTitle()){
        this.title = title;
        this.done = false;
        // Изменения стат. свойств
        Task.count += 1;
    }

    complete(){
        this.done = true;
    }

    // Статический метод
    static getDefaultTitle(){
        return 'Обычная задача';
    }
}

// Статические свойства//
Task.count = 0;

let task1 = new Task('Задача');
let task2 = new Task('Задача 2');
let task3 = new Task();

console.log(task1); // Task {title: "Задача", done: false}
console.log(task2); // Task {title: "Задача 2", done: false}
task1.complete();
console.log(task1); // Task {title: "Задача", done: true}
console.log(Task.count); // 3
console.log(task3); // Task {title: "Обычная задача", done: false}

// GET и SET

class TaskSecond {

    constructor(title = TaskSecond.getDefaultTitle()){
        this.title = title;
        this._done = false;
    }

    get done(){
        return this._done === true ? 'Выполнена' : 'Не выполнена';
    }

    set done(value){
        if(value !== undefined && typeof value === 'boolean'){
            this._done = value;
        }else{
            console.error('Ошибка, укажите значение true или false');
        }
    }
    complete(){
        this._done = true;
    }
}

let task4 = new TaskSecond('Убраться');
console.log(task4.done); // Не выполнена
task4.done = 123; // Ошибка, укажите значение true или false
task4.done = true;
console.log(task4.done); // Выполнена

9. Наследование

class Task{
    constructor(title){
        this._title = title;
        this._done = false;
        Task.count += 1;
    }

    complete(){
        this._done = true;
        console.log(`Задача ${this.title} выполнена `)
    }

    set title(value){
        this._title = value;
    }

    get title(){
        return this._title;
    }

    static getDefaultTitle(){
        return 'Задача';
    }
}

class SubTask extends Task{
    constructor(title,priority = 0){
        super(title);
        this.priority = priority;
    }

    complete(){
        //this._done = true;
        super.complete();
        console.log(`Подзадача ${this.title} выполнена `)
    }
}

Task.count = 0;

let task = new Task();
task.title = 'Learn JS';
let subtask = new SubTask();
subtask.title = 'Learn ES6';

console.log(task); // Task {_title: "Learn JS", _done: false}
console.log(subtask); // SubTask {_title: "Learn ES6", _done: false, priority: 0}

task.complete(); // Задача Learn JS выполнена
subtask.complete(); // Подзадача Learn ES6 выполнена

console.log(SubTask.getDefaultTitle()); // Задача
console.log(Task.count); // 2

10. Стрелочные функции

let add = (x,y) => x + y;
let sqr = x => x*x;
let sometext = () => 'Text';
let log = () => console.log('test');
let multy = (x,y) => {
    let result = x * y;
    return result
};

let getPersone = () => ({name : 'Jack'});

console.log(add(3,2));
console.log(sqr(3));
console.log(sometext());
log();
console.log(multy(3,5));
console.log(getPersone());

(function () {
    console.log('Самовызывающеюся функция: IIFE');
})();
(() => console.log('Самовызывающеюся функция: IIFE'))();


// Массивы

let numbers = [1,2,3,4,5,6,7,8,9,10];

let sum = 0;

numbers.forEach(function (num) {
   sum += num;
});
numbers.forEach(num => {sum += num});

console.log(sum);

// Map - применение функции на каждый элемент массива
let squared = numbers.map(function (n) {
   return n*n;
});

let squared = numbers.map(n => n*n);


console.log(squared);

// Объекты

let Men = {
    name: 'Jhon',
    greet: function(){
        setTimeout(function () {
            console.log(`Hello my name is ${this.name}`); // Hello my name is
            console.log(this); // Window...
        }, 1000);
    }
};

let Men = {
    name: 'Jhon',
    greet: function(){
        setTimeout(() => {
            console.log(`Hello my name is ${this.name}`); // Hello my name is Jhon
            console.log(this); // {name: "Jhon", greet: ƒ}
        }, 1000);
    }
};


Men.greet();

11. Деструктурирующее присваивание. Массивы

// Обычный способ
let languages = ['JavaScript','PHP','SQL','Ruby'];
let js = languages[0];
let php = languages[1];
let sql = languages[2];
let ruby = languages[3];

console.log(js,php,sql,ruby); // JavaScript PHP SQL Ruby

// Попроще
let languages = ['JavaScript','PHP','SQL','Ruby'];
let js,php,sql,ruby;
[js,php,sql,ruby] = languages;
console.log(js,php,sql,ruby); // JavaScript PHP SQL Ruby

// Ещё проще
let languages = ['JavaScript','PHP','SQL','Ruby'];
let [js,php,sql,ruby] = languages;
console.log(js,php,sql,ruby); // JavaScript PHP SQL Ruby

// Ваще изи
let [js,php,sql,ruby] = ['JavaScript','PHP','SQL','Ruby'];
console.log(js,php,sql,ruby); // JavaScript PHP SQL Ruby


let scores = [3,4,5];
let [low, mid, hight , heigher] = scores;
console.log(low,mid,hight,heigher); // 3 4 5 undefined

// Пропуск значений
let scores = [3,4,5];
let [low, , hight] = scores;
console.log(low,hight); // 3 5

// Остаточные данные
let scores = [3,4,5];
let [low, ...all] = scores;
console.log(low,all); // 3 [4, 5]

// Со значение по умолчанию
let scores = [3,4];
let [low, mid, hight = 5] = scores;
console.log(low,mid,hight); // 3 4 5

// Вставка массивов
let scores = [3,4,[5,6]];
let [low, mid, hight] = scores;
console.log(low,mid,hight); // 3 4 [5, 6]

// Вытаскивание массивов
let scores = [3,4,[5,6]];
let [low, mid, [hight,heigher]] = scores;
console.log(low,mid,hight, heigher); // 3 4 5 6

// Функции
function computeScore([low,mid]) {
    console.log(low,mid);
}

computeScore([3,4]); // 3,4

function getScores() {
    return [3,4,5];
}

let [low,mid,hight] = getScores();

console.log(low,mid,hight); // 3 4 5

// Простой switch значений переменных
let yes = 'yes';
let no = 'no';
[yes, no] = [no, yes];

console.log(yes, no); // no yes

12. Деструктурирующее присваивание. Объекты

// Классический вариант
let person = {
    firstName: 'Jhon',
    lastName: 'Black'
};
let firstName = person.firstName;
let lastName = person.lastName;
console.log(firstName,lastName); // Jhon Black

// Тоже самое
// Имена переменных должны совпадать со свойствами объекта
let {firstName, lastName} = person;
console.log(firstName,lastName); // Jhon Black

// Переименовывание переменных
let {firstName: first, lastName: last} = person;
console.log(first,last); // Jhon Black

// Сразу с объектом
let {firstName: first, lastName: last} =  {firstName: 'Jhon', lastName: 'Black'};
console.log(first,last); // Jhon Black

// Значение по умолчанию
let {firstName: first, lastName: last, age = 25} =  {firstName: 'Jhon', lastName: 'Black'};
console.log(first,last, age); // Jhon Black 25*/
// Динамическое создание
let {['first'+'Name']: first, lastName: last, age = 25} =  {firstName: 'Jhon', lastName: 'Black'};
console.log(first,last, age); // Jhon Black 25

// Вложенные объекты
let user = {
    firstName: 'Jhon',
    lastName: 'Black',
    social: {
        facebook: "jblack",
        twitter: "jhoblack",
        phones: {
            phone1: '11-22-33',
            phone2: '22-33-44'
        }
    }
};
let {firstName: first, lastName: last, social: {facebook: fb,twitter: tw, phones: {phone1: ph1, phone2: ph2}},age = 25} = user;
console.log(first,last,fb,tw,ph1,ph2,age); // Jhon Black jblack jhoblack 11-22-33 22-33-44 25

function post(url,{data,cache}){
    console.log(data,cache);
}
let result = post('api/users',  { data: user, cache: false  }); // {firstName: "Jhon", lastName: "Black", social: {…}} false

function post(url,{data: {firstName, lastName},cache}){
    console.log(firstName,lastName,cache);
}
let result = post('api/users',  { data: user, cache: false  }); // Jhon Black false

// Также можно провернуть такое с функцией, которая возвращает литерал объекта
function getInfoUser() {
    return {
        firstName: 'Jhon',
        lastName: 'Black',
        social: {
            facebook: "jblack",
            twitter: "jhoblack",
        }
    }
}
let {firstName, lastName, social: {facebook, twitter: tw}} = getInfoUser();
console.log(firstName,lastName, facebook, tw); // Jhon Black jblack jhoblack

13. Обещания (promise). Отдельная статья.

Поделится
Admin

Recent Posts