隨手記乙個漂亮的code

2022-02-22 07:49:47 字數 1901 閱讀 9396

從前有個**長這樣

if (a) 

} else

}

後來長這樣

if (a && b  || !a && d)
再後來長這樣。

if (a? b : d)
有時候,我們需要從陣列中篩選一些東西,filter當然可以,但是有些定製化的東西就很難,而且,在foreach中不能return。every 解決foreach中的return

array.every( item =>  else 

})

不過可能不容易看懂

!~ -1 // true

!~[1].indexof(1) // false

2次執行間隔為x ms

var tr = function (time, fn) 

tr.prototype._flushifneeded = function()

this.fn(this.buffer.pop());

this.buffer = ;

this._lasttriggertime = date.now();

settimeout(this._flushifneeded.bind(this), this.time);

}tr.prototype.trigger =function (arr)

var nf = new tr(1000, function(arr));

nf.trigger('hallo');

nf.trigger('hallo');

nf.trigger('hallo');

function deepclone(obj);

for(var key in obj)else

} return res;

}

function bind (context)  else 

} // 實現繼承,讓bound函式生成的例項通過原型鏈能追溯到target函式

// 即 例項可以獲取/呼叫target.prototype上的屬性/方法

var empty = function () {}

empty.prototype = target.prototype

bound.prototype = new empty() // 這裡如果不加入empty,直接bound.prototype = target.prototype的話.改變bound.prototype則會影響到target.prototype,原型繼承基本都會加入這麼乙個中間物件做屏障

bound.prototype.constructor = bound; // constructor修正,防止呼叫constructor函式出錯

return bound

}

某個正常的提交

git add . 

git commit -m "feature a"

git log --graph --pretty=oneline --abbrev-commit

如果我的feature a有bug可以這樣操作:

git add .

git commit --fixup 8831bd1 -> feature a的id

然後用autosquash合併兩個commit

git rebase -i --autosquash 4dd17ad -> feature a的前乙個id
git會自動幫你找出fixup的提交,和正常提交合併,你只需要在vim裡面直接儲存就可以了。

隨手記乙個問題

f12點開控制台檢視響應體發現檔名亂碼,推測是因為瀏覽器沒能識別檔名。解決辦法 在對客戶端寫檔案之前,對檔名進行url編碼 response.addheader content disposition attachment filename filename 其中filename包含字尾。strin...

我的工作隨手記(一)

更新了客戶端之後使用者進入還是老版本的,或者因為快取的部分的js而造成奇怪的問題,雖然cocoscreator可以勾選md5 cache讓生成的東西多乙個md5效驗碼,可是實際使用中還是會碰到快取的問題。這一度讓我很是崩潰。然後各種嘗試之後覺得有可能是html檔案本地快取了,造成我更新上去的js指令...

告白 乙個loser的手記

真不知道怎麼會是這樣?回味以前的種種,到最後才發覺你是如此的模樣,如此的狼狽和破敗,如此不堪一擊。你曾經以為和高手的差別不過絲毫,但今天看過來,高手奪得了頂峰,而你確一直在這裡徘徊,這就是一直在走下坡路,從現在開始還不算太晚,但很多事情可能因此無法挽回了。打完昨天的bc,你突然覺得,原來自己竟然也弱...