This file contains hidden or 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
const PENDING = "PENDING"; | |
const FULFILLED = "FULFILLED"; | |
const REJECTED = "REJECTED"; | |
// Promise 的处理函数 | |
const resolvePromise = (promise2, x, resolve, reject) => { | |
if (promise2 === x) { | |
return reject( | |
new TypeError("Chaining cycle detected for promise #<Promise>") | |
); |
This file contains hidden or 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
{"lastUpload":"2022-01-09T12:30:22.629Z","extensionVersion":"v3.4.3"} |
This file contains hidden or 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
const getListener = (fn, context) => ({ | |
fn, | |
context | |
}); | |
const addListener = (...rest) => { | |
const [emitter, event, fn, context] = rest; | |
const listener = getListener(fn, context || emitter); | |
let events = emitter.events; |
This file contains hidden or 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
/** | |
* 冒泡排序 | |
* 时间复杂度:O(n^2) | |
* 空间复杂:O(1) | |
* 稳定性:稳定 | |
*/ | |
function bubbleSort(originArr) { | |
const length = originArr.length; | |
if (!length || length < 2) return originArr; | |
const arr = JSON.parse(JSON.stringify(originArr)); |
This file contains hidden or 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 Router { | |
constructor() { | |
this.routers = {}; | |
this.currentUrl = ''; | |
} | |
router(path, callback) { | |
this.routers[path] = callback || function() {}; | |
} | |
updateView() { | |
this.currentUrl = location.hash.slice(1) || '/'; |
This file contains hidden or 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 videoSupport() { | |
if (!!document.createElement('video').canPlayType) { | |
return true; | |
} else { | |
return false; | |
} | |
} |
This file contains hidden or 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 reg = RegExp('^(\\w){6,20}$'); |
This file contains hidden or 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 toString = Object.prototype.toString; | |
var isType = function (type) { | |
return function(obj) { | |
return toString.call(obj) == '[object ' + type + ']'; | |
} | |
} | |
var isString = isType('String'), | |
isNumber = isType('Number'), |
This file contains hidden or 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 dateCls { | |
constructor(x) { | |
this.x = x; | |
this.date = new Date(); | |
} | |
Now () { | |
return this.date.toLocaleString() | |
.substr(0, 10) | |
.replace(/[\u4E00-\u9FA5]+/g, '') |
This file contains hidden or 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 downloadJSAtOnload() { | |
var element = document.createElement("script"); | |
element.src = "defer.js"; | |
document.body.appendChild(element); | |
} | |
if (window.addEventListener) { | |
window.addEventListener("load", downloadJSAtOnload, false); | |
} else if (window.attachEvent) { | |
window.attachEvent("onload", downloadJSAtOnload); |
NewerOlder