<!-- --> <div id="main"> <div class="article"> <div class="header"> <h1>Blog post</h1> <p>Published: <span>21st Feb, 2015</span></p> </div> <p>…</p> </div> </div> <!-- --> <main> <article> <header> <h1>Blog post</h1> <p>Published: <time datetime="2015-02-21">21st Feb, 2015</time></p> </header> <p>…</p> </article> </main>
<!-- --> <h1> <figure> <img alt=Company src=logo.png> </figure> </h1> <!-- --> <h1> <img alt=Company src=logo.png> </h1>
<!-- --> <!doctype html> <html lang=en> <head> <meta http-equiv=Content-Type content="text/html; charset=utf-8" /> <title>Contact</title> <link rel=stylesheet href=style.css type=text/css /> </head> <body> <h1>Contact me</h1> <label> Email address: <input type=email placeholder=you@email.com required=required /> </label> <script src=main.js type=text/javascript></script> </body> </html> <!-- ( ) --> <!doctype html> <html lang=en> <meta charset=utf-8> <title>Contact</title> <link rel=stylesheet href=style.css> <h1>Contact me</h1> <label> Email address: <input type=email placeholder=you@email.com required> </label> <script src=main.js></script> </html>
<!-- --> <h1><img alt="Logo" src="logo.png"></h1> <!-- --> <h1><img alt="My Company, Inc." src="logo.png"></h1>
<!-- --> <!doctype html> <title>, .</title> <!-- --> <!doctype html> <html lang=ru> <meta charset=utf-8> <title>, .</title> </html>
<!-- --> <!doctype html> <meta charset=utf-8> <script src=analytics.js></script> <title>Hello, world.</title> <p>...</p> <!-- --> <!doctype html> <meta charset=utf-8> <title>Hello, world.</title> <p>...</p> <script src=analytics.js></script>
/* */ div { color: red } /* */ div { color: red; }
/* */ div { width: 100%; padding: 10px; box-sizing: border-box; } /* */ div { padding: 10px; }
/* */ img { display: block; } /* */ img { vertical-align: middle; }
/* */ div { width: 100px; position: absolute; right: 0; } /* */ div { width: 100px; margin-left: auto; }
display: block; display: flex; position: relative; position: sticky; position: absolute; position: fixed;
/* */ div:first-of-type :last-child > p ~ * /* */ div:first-of-type .info
/* */ img[src$=svg], ul > li:first-child { opacity: 0; } /* */ [src$=svg], ul > :first-child { opacity: 0; }
/* */ .bar { color: green !important; } .foo { color: red; } /* */ .foo { color: red; } .foo.bar { color: green; }
/* */ li { visibility: hidden; } li:first-child { visibility: visible; } /* */ li + li { visibility: hidden; }
/* */ div h1, div p { text-shadow: 0 1px 0 #fff; } /* */ div { text-shadow: 0 1px 0 #fff; }
/* */ div { transition: all 1s; top: 50%; margin-top: -10px; padding-top: 5px; padding-right: 10px; padding-bottom: 20px; padding-left: 10px; } /* */ div { transition: 1s; top: calc(50% - 10px); padding: 5px 10px 20px; }
/* */ :nth-child(2n + 1) { transform: rotate(360deg); } /* */ :nth-child(odd) { transform: rotate(1turn); }
/* */ div { transform: scale(2); -webkit-transform: scale(2); -moz-transform: scale(2); -ms-transform: scale(2); transition: 1s; -webkit-transition: 1s; -moz-transition: 1s; -ms-transition: 1s; } /* */ div { -webkit-transform: scale(2); transform: scale(2); transition: 1s; }
/* */ div:hover { animation: move 1s forwards; } @keyframes move { 100% { margin-left: 100px; } } /* */ div:hover { transition: 1s; transform: translateX(100px); }
/* */ div { margin: 0px; font-size: .9em; line-height: 22px; transition: 500ms; } /* */ div { margin: 0; font-size: .9rem; line-height: 1.5; transition: .5s; }
/* */ div { color: hsl(103, 54%, 43%); } /* */ div { color: #5a3; }
/* */ div::before { content: url(white-circle.svg); } /* */ div::before { content: ""; display: block; width: 20px; height: 20px; border-radius: 50%; background: #fff; }
/* */ div { // position: relative; transform: translateZ(0); } /* */ div { /* position: relative; */ will-change: transform; }
/* ( ) */ const arr = [1, 2, 3, 4]; const len = arr.length; var i = -1; var result = []; while (++i < len) { var n = arr[i]; if (n % 2 > 0) continue; result.push(n * n); } /* */ const arr = [1, 2, 3, 4]; const isEven = n => n % 2 == 0; // const square = n => n * n; // : (param1, param2, …, paramN) => expression const result = arr.filter(isEven).map(square);
/* */ const merge = (target, ...sources) => Object.assign(target, ...sources); merge({ foo: "foo" }, { bar: "bar" }); // => { foo: "foo", bar: "bar" } /* */ const merge = (...sources) => Object.assign({}, ...sources); merge({ foo: "foo" }, { bar: "bar" }); // => { foo: "foo", bar: "bar" }
/* */ const toArray = obj => [].slice.call(obj); /* */ const toArray = (() => Array.from ? Array.from : obj => [].slice.call(obj) )();
/* */ if (x === undefined || x === null) { /* ... */ } /* */ if (x == undefined) { /* ... */ }
/* */ const sum = arr => { var sum = 0; var i = -1; for (;arr[++i];) { sum += arr[i]; } return sum; }; sum([1, 2, 3]); // => 6 /* */ const sum = arr => arr.reduce((x, y) => x + y); sum([1, 2, 3]); // => 6
/* */ const createDivs = howMany => { while (howMany--) { document.body.insertAdjacentHTML("beforeend", "<div></div>"); } }; createDivs(5); /* */ const createDivs = howMany => [...Array(howMany)].forEach(() => document.body.insertAdjacentHTML("beforeend", "<div></div>") ); createDivs(5); /* */ const createDivs = howMany => { if (!howMany) return; document.body.insertAdjacentHTML("beforeend", "<div></div>"); return createDivs(howMany - 1); }; createDivs(5);
/* */ const sortNumbers = () => Array.prototype.slice.call(arguments).sort(); /* */ const sortNumbers = (...numbers) => numbers.sort();
const greet = (first, last) => `Hi ${first} ${last}`; const person = ["John", "Doe"]; /* */ greet.apply(null, person); /* */ greet(...person);
/* */ ["foo", "bar"].forEach(func.bind(this)); /* */ ["foo", "bar"].forEach(func, this);
/* */ const person = { first: "John", last: "Doe", greet() { const full = function() { return `${this.first} ${this.last}`; }.bind(this); return `Hello ${full()}`; } } /* */ const person = { first: "John", last: "Doe", greet() { const full = () => `${this.first} ${this.last}`; return `Hello ${full()}`; } }
/* */ const result = [1, 2, 3].map(num => String(num)); // => ["1", "2", "3"] /* */ const result = [1, 2, 3].map(String); // string
const plus1 = a => a + 1; const mult2 = a => a * 2; /* */ mult2(plus1(5)); // => 12 /* */ const pipeline = (...funcs) => val => funcs.reduce((a, b) => b(a), val); const addThenMult = pipeline(plus1, mult2); addThenMult(5); // => 12
/* */ const contains = (arr, value) => Array.prototype.includes ? arr.includes(value) : arr.some(el => el === value); contains(["foo", "bar"], "baz"); // => false /* */ const contains = (() => Array.prototype.includes ? (arr, value) => arr.includes(value) : (arr, value) => arr.some(el => el === value) )(); contains(["foo", "bar"], "baz"); // => false
/* */ var me = new Map(); me.set("name", "Ben").set("country", "Belgium"); /* */ const me = new Map(); me.set("name", "Ben").set("country", "Belgium");
/* */ var grade, result = 50; if (result < 50) grade = "bad"; else if (result < 90) grade = "good"; else grade = "excellent"; // grade = "good"; /* */ let result = 50; const grade = (() => { if (result < 50) return "bad"; if (result < 90) return "good"; return "excellent"; })(); // grade = "good";
const shared = { foo: "foo" }; const obj = Object.create(shared, { bar: { value: "bar", enumerable: true } }); /* */ for (var prop in obj) { if (obj.hasOwnProperty(prop)) console.log(prop); // => bar } /* */ Object.keys(obj).forEach(prop => console.log(prop));
/* */ const me = { name: "Ben", age: 30 }; var meSize = Object.keys(me).length; meSize; // => 2 me.country = "Belgium"; // meSize++; meSize; // => 3 /* */ const me = new Map(); me.set("name", "Ben"); me.set("age", 30); me.size; // => 2 me.set("country", "Belgium"); me.size; // => 3
/* */ const sum = a => b => a + b; sum(5)(3); // => 8 /* */ const sum = (a, b) => a + b; sum(5, 3); // => 8
/* */ foo || doSomething(); /* */ void function() { /* IIFE */ }(); /* */ const n = ~~3.14; /* */ if (!foo) doSomething(); /* */ (function() { /* IIFE */ }()); /* */ const n = Math.floor(3.14);
/* */ let last = arr[arr.length - 1]; /* */ const product = (a, b) => a * b; const triple = n => n * 3; /* */ const first = arr => arr[0]; // => first(arr); const last = arr => first(arr.slice(-1)); // => last(arr); /* */ const product = (a, b) => a * b; const triple = product.bind(null, 3);
/* */ var _ = require("underscore"); _.compact(["foo", 0])); _.unique(["foo", "foo"]); _.union(["foo"], ["bar"], ["foo"]); /* */ const compact = arr => arr.filter(el => el); const unique = arr => [...Set(arr)]; const union = (...arr) => unique([].concat(...arr)); compact(["foo", 0]); unique(["foo", "foo"]); union(["foo"], ["bar"], ["foo"]);
Source: https://habr.com/ru/post/275729/
All Articles