This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* [惰性单例] | |
* @param {Function} fn [需要使用单例模式的函数] | |
* @return {Function} | |
*/ | |
function getSingle(fn) { | |
var ret | |
return (...args) => ret || (ret = fn.apply(this, args)) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 检测浏览器是否支持某个css属性 | |
* @param {[String]} prop [属性名] | |
* @param {[String]} value [属性值] | |
* @return {[Boolean]} true:支持 否则不支持 | |
*/ | |
function cssSupported(prop, value) { | |
const d = document.createElement('div') | |
d.style[prop] = value | |
return d.style[prop] === value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 生成uuid | |
* @return {[string]} uuid | |
*/ | |
function generateUUID() { | |
function s4() { | |
return Math.floor((1 + Math.random()) * 0x10000) | |
.toString(16) | |
.substring(1) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* ScrollFix v0.1 | |
* http://www.joelambert.co.uk | |
* | |
* Copyright 2011, Joe Lambert. | |
* Free to use under the MIT license. | |
* http://www.opensource.org/licenses/mit-license.php | |
*/ | |
var ScrollFix = function(elem) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function cacheProxyFactory(fn) { | |
var cache = {} | |
return function() { | |
var args = [].join.call(arguments, ',') | |
if (args in cache) { | |
return cache[args] | |
} | |
return cache[args] = fn.apply(this, arguments) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var synchronousFile = function(id) { | |
console.log('开始同步文件,id 为: ' + id); | |
} | |
// 虚拟代理http请求 | |
var proxySynchronousFile = (function() { | |
var cache = [], timer | |
return function(id) { | |
cache.push(id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class EventEmitter { | |
constructor() { | |
this.clientList = {} | |
} | |
on(key, fn) { | |
if (!this.clientList[key]) { | |
this.clientList[key] = [] | |
} | |
this.clientList[key].push(fn) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function optionalChaining(obj, chain) { | |
return chain | |
.split('.') | |
.reduce(function(acc, val) { | |
return acc ? acc[val] : undefined; | |
}, obj); | |
} | |
var user = { address: { street: 'No.969 West WenYi Road', }, a: { b: { c: 2 } }, } | |
var ret = optionalChaining(user, 'address'); | |
console.log(ret) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.requestAnimFrame = (function requestAnimFrame() { | |
return window.requestAnimationFrame || | |
window.webkitRequestAnimationFrame || | |
window.mozRequestAnimationFrame || | |
function simulation(callback) { | |
window.setTimeout(callback, 1000 / 60) | |
} | |
}()) | |
function scrollToY(scrollTargetY = 0, speed = 2000, easing = 'easeOutSine') { |
OlderNewer