Skip to content

Instantly share code, notes, and snippets.

@mrded
Last active December 30, 2015 01:09
Show Gist options
  • Save mrded/7754622 to your computer and use it in GitHub Desktop.
Save mrded/7754622 to your computer and use it in GitHub Desktop.
Hipster's code snippets.
// 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