var?day=(new?Date).getDay()===0;
//傳統(tǒng)if語句
if?(day)?{
?alert('Today is Sunday!');
};
//運(yùn)用邏輯與代替if
day&&alert('Today is Sunday!');
年月日 巧妙轉(zhuǎn)化
https://segmentfault.com/q/1010000011341804
//對象深拷貝
var cloneObj = function(obj){
? var str, newobj = obj.constructor === Array ? [] : {};
? if(typeof obj !== 'object'){
? return;
? } else if(window.JSON){
? str = JSON.stringify(obj), //系列化對象
? newobj = JSON.parse(str); //還原
? } else {
? for(var i in obj){
? newobj[i] = typeof obj[i] === 'object' ??
? cloneObj(obj[i]) : obj[i];?
? }
? }
? return newobj;
};
數(shù)組拷貝
Array.prototype.slice.call(a)