Skip to content

Instantly share code, notes, and snippets.

:octocat:
...

Michael Gerstmann webdesignberlin

:octocat:
...
Block or report user

Report or block webdesignberlin

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View jsx-object-literal.jsx
function WhySoManyProps(props) {
const user = extractUser(props);
const fudge = calculateFudge();
const bits = computeBits();
// This is soooooo redundant.
return <SomeComponent user={user} fudge={fudge} bits={bits} />;
}
function Shorthand(props) {
View no-bind-util-object.js
const moment = require('moment');
const PERIOD = moment.duration(3, 'days');
module.exports = {
PERIOD,
isWithinPeriod(test) {
return moment().add(PERIOD).isAfter(test);
},
};
View destructuring-cli.js
#!/usr/bin/env node
// skip the first two args as they are node and this script
const [,,filepath] = process.argv;
doSomethingFSLike(filepath);
View branches-and-leaves.js
const {
topLevel: {
intermediate, // declaration of intermediate
intermediate: {
nested // declaration of nested
}
}
} = {
topLevel: {
intermediate: {
View default-default.js
function defaults({ a = 1, b = 2 } = {}) {
console.log('a', a);
console.log('b', b);
}
defaults();
// a 1
// b 2
defaults({ a: 42, b: 32 });
View simple-destructuring-default-params.js
function defaults({ a, b } = { a: 1, b: 2 }) {
console.log('a', a);
console.log('b', b);
}
defaults();
// a 1
// b 2
defaults({ a: 42, b: 32 });
View destructuring-rename.js
// simple renaming to avoid collisions or just as a preference.
const a = 5;
const { a: b } = { a: 3 };
console.log(b); // prints 3
// rename for another API and use enhanced object literal notation.
function verifyUser({ userId: id }) {
return User.update({ id, verified: true });
}
View simple-es6.js
// can destructure arrays
const [a, b] = [1,2]; // a = 1, b = 2
// can destructure object keys
const { a } = { a: 3 }; // a = 3
// even function parameters
function foo({ a }) {
console.log(a);
}
@webdesignberlin
webdesignberlin / addClass.js
Created Oct 12, 2016
Javascript Add/Remove Class from selector
View addClass.js
function addClass(selector, newClass) {
// get all elements that match our selector
elements = document.querySelectorAll(selector);
// add class to all chosen elements
for (var i=0; i<elements.length; i++) {
elements[i].classList.add(newClass);
}
}
View visuallyhidden.css
.visuallyhidden:not(:focus):not(:active) {
position: absolute;
width: 1px;
height: 1px;
margin: -1px;
border: 0;
padding: 0;
clip-path: inset(100%);
You can’t perform that action at this time.