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
| var module = (function() { | |
| var _private = { | |
| i: 5, | |
| get: function() { | |
| console.log('Текущее значение:' + this.i); | |
| }, | |
| set: function(val) { | |
| this.i = val; | |
| }, | |
| run: function() { |
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 greeter = { | |
| doGreeting(msg) { | |
| console.log(msg); | |
| } | |
| }; | |
| const newYearGreeter = { | |
| setYear(year) { | |
| this.year = year; | |
| }, |
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 bind(func, context) { | |
| return function() { | |
| return func.apply(context, arguments); | |
| }; | |
| } | |
| var user = { | |
| firstName: "Вася", | |
| sayHi: function() { | |
| alert( this.firstName ); |
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
| /** | |
| * Tricky code with object reference | |
| * | |
| * @Reference: | |
| * http://ejohn.org/apps/learn/#13 | |
| * http://ejohn.org/apps/learn/#14 | |
| * http://stackoverflow.com/questions/22216159/an-object-null-and-behaviour-in-javascript | |
| */ | |
| // Program 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 debounce(fn, delay) { | |
| let timeout; | |
| return function(...args) { | |
| const context = this; | |
| clearTimeout(timeout); | |
| timeout = setTimeout(() => fn.apply(context, args), delay); | |
| } | |
| } |
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
| // Author @realmyst | |
| function declOfNum(number, titles) { | |
| cases = [2, 0, 1, 1, 1, 2]; | |
| return titles[ (number%100>4 && number%100<20)? 2 : cases[(number%10<5)?number%10:5] ]; | |
| } | |
| // use | |
| declOfNum(count, ['найдена', 'найдено', 'найдены']); | |
| // Author @retyui |
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 curry = fn => { | |
| const arity = fn.length; | |
| return (...args) => { | |
| if (args.length >= arity) { | |
| return fn(...args); | |
| } else { | |
| return (...secondArgs) => { | |
| return fn(...[...args, ...secondArgs]); | |
| } |
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 checkPermissionDecorator(f) { | |
| return function() { | |
| if (isAdmin()) { | |
| return f.apply(this, arguments); | |
| } | |
| alert( 'Недостаточно прав' ); | |
| } | |
| } | |
| function save() { ... } |
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
| git branch -m old_branch new_branch # Rename branch locally | |
| git push origin :old_branch # Delete the old branch | |
| git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote |
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
| // Live example: https://goo.gl/xJblcx | |
| .Q(@breaks; @rules;) { | |
| // If there's only one breakpoint: | |
| & when (length(@breaks) = 1) { | |
| @query: ~"(min-width: @{breaks}px)"; | |
| @media screen and @query {@rules();}; | |
| } | |
| // If there's two breakpoints: | |
| & when (length(@breaks) = 2) { |
OlderNewer