Skip to content

Instantly share code, notes, and snippets.

View limianwang's full-sized avatar
🏠
Working Remotely

Limian Wang limianwang

🏠
Working Remotely
View GitHub Profile
const View = styled.View`
padding-top: ${({ top }) => (top || 5)}px;
padding-bottom: ${({ bottom }) => (bottom || 5)}px;
padding-right: ${({ right }) => (right || 5)}px;
padding-left: ${({ left}) => (left || 5)}px;
background-color: ${props => props.transparent ? 'black' : '#ffffff'};
margin-right: 0px;
margin-left: 0px;
margin-top: 0px;
margin-bottom: 0px;
@limianwang
limianwang / apply_call.md
Created August 5, 2015 21:42
Apply VS Call

While starting at my new job, I have heard constantly the question for the difference between Function.apply and Function.call.

Fundamentally, they are equal. Nothing is different in what happens to the function itself. The difference is, though, about how the function will be called.

Function.prototype.apply expects and array of arguments, while Function.prototype.call expects a list/component for the arguments.

function test(a, b, c) {
  console.log(this); // scope
 console.log(Array.prototype.slice.call(arguments));
@limianwang
limianwang / Bind.md
Last active August 29, 2015 14:26
Tutorial: Bind Function

In the powerful world of JS, you can do a lot of crazy things with Bind/Apply/Call. Here, I can show a small example so that it can be easily understood.

function test1(a, b, c) {
  console.log(Array.prototype.slice.call(arguments));
  // What will this output?
}

function test2(fn) {
 fn();
@limianwang
limianwang / gist:90da0a4276c64bc9e17b
Last active August 29, 2015 14:12
Creating truly asynchronous functions
/*
When coding in Node.js, you will often/most likely be dealing with some I/O, which involves asynchronous processes. Therefore, building a standard for coding is paramount.
Consider the following code:
*/
var fs = require('fs');
function logA(command, data, done) {
if(command === 'write') {
'use strict';
var cluster = require('cluster');
if(cluster.isMaster) {
console.log('master', process.pid);
var worker = cluster.fork();
console.log('forked child pid: ', worker.process.pid);
} else {
console.log('child', process.pid);
@limianwang
limianwang / Output
Last active December 2, 2016 00:16
utility class
$ ./node_modules/mocha/bin/mocha -R spec -u bdd test_index.js
test
✓ should be able to get object back
1 passing (9ms)