Last active
December 30, 2015 01:09
-
-
Save mrded/7754622 to your computer and use it in GitHub Desktop.
Hipster's code snippets.
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
// Call method. | |
var method = (success ? 'start' : 'stop'); | |
obj[method](); | |
// Concatenation. | |
['first', 'name'].join(' '); // = 'first name'; | |
['milk', 'coffee', 'suger'].join(', '); // = 'milk, coffee, suger' | |
// Value by default. | |
var name = myName || 'No name'; // Returns 'No name' when myName is null or undefined | |
var doStuff = function(options) { | |
options = options || {}; | |
// ... | |
}; | |
// && | |
if (isThisAwesome) { | |
alert('yes'); // it's not | |
} | |
isThisAwesome && alert('yes'); | |
// Another case. | |
var aCoolFunction = undefined; | |
aCoolFunction && aCoolFunction(); // не запустится, но и не вылетит с ошибкой | |
// Native light templating. | |
var firstName = 'foo'; | |
var screenName = 'bar' | |
var template = 'Hi, my name is {first-name} and my twitter screen name is @{screen-name}'; | |
var txt = template.replace('{first-name}', firstName) | |
.replace('{screen-name}', screenName); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment