Skip to content

Instantly share code, notes, and snippets.

View casprwang's full-sized avatar

Casper Wang casprwang

View GitHub Profile
@casprwang
casprwang / factory.js
Created January 5, 2017 03:21
right one
const dog = () => {
const sound = 'woof';
return {
talk: () => console.log(sound)
};
};
const bark = dog();
bark.talk();
@casprwang
casprwang / composition.js
Created January 5, 2017 20:33
comment is a verbose function
// const barker = (state) =>
// const barker = state => ({
// bark: () => console.log(`Woof, I am ${state.name}`)
// });
const barker = state => ({
bark: () => console.log(`Woof, I am an ${state.name}`)
});
greet();
a();
const a = function () {
console.log('h1');
};
function greet() {
console.log('h2');
}
@casprwang
casprwang / expression.js
Created January 5, 2017 21:16
pass val to an function inside of an object
// greet();
// a();
const a = function () {
console.log('h1');
};
function greet() {
console.log('h2');
}
@casprwang
casprwang / obj2.js
Created January 5, 2017 21:25
invoke a function by letting the function in
const a = x => console.log(x);
a(() => console.log('h1'));
// create a function on the fly
console.log(() => console.log('this is stupid'));
const b = x => x();
b(() => console.log('this is even stupier'));
@casprwang
casprwang / gist:5865641ea41472e3947e9c9f3e02723f
Created January 14, 2017 03:23
get css value command in Chrome Tool console
getComputedStyle(document.getElementById('blue')).getPropertyValue('width')
// export default l => () => console.log(12)
// export default l => (console.log('12'))
// export default l => ({ ll: () => 12})
// const l = () => 2
// // console.log(l())
// export { l }
function higher (d) ({
add3: () => (d + 3)
})
const higher = (d) => ({
add3: () => d + 3
})
class higher {
constructor (d) {
const counter = () => ({
count: s => {
return 'haha' + s
}
})
class counter {
count(s) {
return 'haha' + s
}
let str = 'sajldfj jksdfajl akljf kdaj kjfsak jk'
let regex = /\w+/g
console.log(str.match(regex))
console.log(str.match(NaN))
console.log(str.match(/jjslkdjfalkj/))