Skip to content

Instantly share code, notes, and snippets.

View fuchao2012's full-sized avatar
🎯
Focusing

zheng fuchao2012

🎯
Focusing
View GitHub Profile
@fuchao2012
fuchao2012 / diff.md
Created April 10, 2017 10:43
bind apply call 的区别

相同点

apply 、 call 、bind 三者都是用来改变函数的this对象的指向的; apply 、 call 、bind 三者第一个参数都是this要指向的对象,也就是想指定的上下文; apply 、 call 、bind 三者都可以利用后续参数传参;

不同点

bind 是返回对应函数,便于稍后调用;

@fuchao2012
fuchao2012 / square.css
Created April 10, 2017 10:10
用css 实现一个正方形布局
/*实现一个响应式的正方形布局,第一反应*/
.container{
width:100%;
height:100vw;
}
/*
不过这货兼容性...只能说还行
//Thanks to https://javascriptweblog.wordpress.com/2011/08/08/fixing-the-javascript-typeof-operator/
// typeof now
// Undefined => "undefined"
// Null => "object" *** fu*king mistake here ***
// Boolean => "boolean"
// Number => "number"
// String => "string"
// Object(uncallable) => "object"
// Array => "object"
@fuchao2012
fuchao2012 / gist:3cc80285715739a42af2745295751418
Created March 13, 2017 03:07 — forked from jimbojsb/gist:1630790
Code highlighting for Keynote presentations

Step 0:

Get Homebrew installed on your mac if you don't already have it

Step 1:

Install highlight. "brew install highlight". (This brings down Lua and Boost as well)

Step 2:

@fuchao2012
fuchao2012 / isEmptyObject.js
Created March 3, 2017 06:16
isEmptyObject
// ES5-
if(!Object.prototype.isEmptyObject){
Object.prototype.isEmptyObject = function(value){
for (var key in value) {
if (hasOwnProperty.call(value, key)) {
return false;
}
}
return true;
}
if(!String.prototype.trim){ //ES5 IE9+
//regexp
String.prototype.trim=function(){
return this.replace(/(^\s+)|(\s+$)/g, '')
}
}
@fuchao2012
fuchao2012 / shuffle.js
Last active February 24, 2017 09:37
Random Array
//Fisher-Yates 舒服了
Array.prototype.shuffle=function(){
let results = [], temp, acc = this.length >>> 0
while(acc > 0){
temp = (Math.random() * acc--)>>>0
[this[acc],this[temp]] = [this[temp], this[acc]]
}
return this
}
@fuchao2012
fuchao2012 / symbol.js
Created February 23, 2017 09:10
Symbol
// demo
let privateDataStore = {
set(val){
let key = Symbol(Math.random().toString(32).substr(2))
this[key]=val
return key
}
get(key){
return this[key]
}
@fuchao2012
fuchao2012 / fetch.js
Last active February 23, 2017 08:48
promise-fetch
let fetch = ()=>{
return new Promise((resolve, reject)=>{
api.call('fetch_data', (err, data)=>{
if(err) return reject(err)
resolve(data)
})
})
}
fetch('data/url/to')
@fuchao2012
fuchao2012 / fib.js
Created February 23, 2017 07:39
fib-generator tags: #ES6
function* fib(){
let a=1, b=1
yield a
yield b
while(true){
let next = a+b
a=b
b=next
yield next
}