Skip to content

Instantly share code, notes, and snippets.

DarwinniwraD / getUnflattenToTree.js
Last active December 3, 2019 13:47
array of objects to tree
export default const getUnflatten = (arr, idFieldName, parentFieldName) => (arr, parentid) => arr.reduce((all, item) => item[parentFieldName] === parentid ? all.concat({...item, children: getUnflatten(arr, item[idFieldName])}): all, [] )
DarwinniwraD /
Created January 3, 2018 08:23 — forked from davfre/
git commandline cheat-sheet
DarwinniwraD /
Last active November 24, 2017 02:51 — forked from alexpchin/
Create a new repository on the command line

Setting up a new Git Repo

##Create a new repository on the command line

git init
git add
git commit -m "first commit"

git remote add origin

DarwinniwraD / git_merge_local.txt
Last active May 23, 2017 06:13 — forked from vladimirtsyupko/gist:10964772
Git force pull to overwrite local files
git fetch --all
git reset --hard origin/master
git pull origin master


众所周知,js中复制包括浅复制(Shallow Clone)和深复制(Deep Clone)两种,深复制的出现主要针对复杂数据结构,如数组和对象,其中浅复制就是运用赋值运算方式(“=”),为新对象引用所有的源对象属性,这不会产生新的对象,只是一个对象引用(reference)。而深复制则相对复杂一些,它是将所有的原始数据类型,机器所有的对象引用复制到新的对象中,这种复制最终会形成两个对象.关于两种复制的方法的论述已经有许多了,无外乎有以下三种:

  1. 第三方库,如underscore.js,jquery, loadsh

  2. JSON大法

  3. js原生方法

  4. 关于第三方库的复制方法

  1. jQuery
//This is a complete guide for centering a div with CSS.
//1.Centering in CSS: A Complete Guide(
//2.How To Center Anything With CSS(
//3.CSS layout: tricks and layout techniques in ‘Learn CSS Layout’(
//4.Absolute Centering(
A (very) WIP collection of optimized/recommended jQuery plugin patterns
from @addyosmani, @cowboy, @ajpiano and others.
Whilst the end-goal of this gist is to provide a list of recommended patterns, this
is still very much a work-in-progress. I am not advocating the use of anything here
until we've had sufficient time to tweak and weed out what the most useful patterns