This file contains 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 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 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 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 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 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 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 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 singleton = Symbol(); | |
const singletonEnforcer = Symbol(); | |
class Singleton { | |
constructor(enforcer) { | |
if (enforcer !== singletonEnforcer) { | |
throw new Error('Cannot construct singleton'); | |
} | |
this._type = 'Singleton'; |
This file contains 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 https://github.com/vasanthk/js-bits/blob/master/js/currying.js | |
* Currying refers to the process of transforming a function with multiple arity (# or args a fn accepts) | |
* into the same function with less arity. | |
* | |
* Briefly, currying is a way of constructing functions that allows partial application of a function’s arguments. | |
* What this means is that you can pass all of the arguments a function is expecting and get the result, | |
* or pass a subset of those arguments and get a function back that’s waiting for the rest of the arguments. | |
* | |
* Currying vs Partial Application |
This file contains 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