Skip to content

Instantly share code, notes, and snippets.

View Teemwu's full-sized avatar
🎯
Focusing

Teemwu Teemwu

🎯
Focusing
View GitHub Profile
@Teemwu
Teemwu / ticker.ts
Last active January 13, 2023 03:37
requestAnimationFrame instead of setTimeout and setInterval
export default class Ticker {
static RAF: any = null
static CAF: any = null
static prefixs = ['webkit', 'moz', 'o', 'ms']
constructor() {
Ticker.RAF = this.getRequestAnimationFrame()
Ticker.CAF = this.getCancelAnimationFrame()
}
@Teemwu
Teemwu / index.js
Last active July 13, 2022 10:22
display_all_github_issue_detail
/**
* Display all issue's detail in one page by iframe
* tips:
* 1. Disalbe 'x-frame-options' by chrome extension, you can install https://chrome.google.com/webstore/detail/ignore-x-frame-headers/gleekbfjekiniecknbkamfmkohkpodhe
* 2. Compress below code to one line by Javscript online Compressor, you can use https://jscompress.com/
* 3. Copy the compressed code and paste to chrome address bar then save as a bookmark
* 4. Open the issue list page then click that bookmark
* 5 .If you want to cancel display, retry step 4 again
*/
javascript: (function () {
@Teemwu
Teemwu / codeswing.json
Last active April 27, 2022 01:01
获取菜单目录路径
{
"scripts": [],
"showConsole": true
}
@Teemwu
Teemwu / polling.ts
Last active December 30, 2021 07:03
封装各种轮询
export default class Polling {
private timer: number
private interval: number
private times: number
constructor(interval = 5e3, times = -1) {
this.interval = interval
this.times = times
@Teemwu
Teemwu / _new.js
Last active September 16, 2021 04:14
手写 new 操作符
'use strict';
/**
* 手写 new 操作符
* 注:暂不支持 Class 传入
* @param {*} fn 函数
* @param {...any} args 其它参数
* @returns function
*/
function _new(fn, ...args) {
// 创建拥有 fn 原型的对象
@Teemwu
Teemwu / _all.js
Last active September 15, 2021 07:40
手写 Promise.all 和 Promise.race
'use strict';
/**
* 手写实现 Promise.all 方法
* @param {string|array} values 一个可迭代对象
* @returns promise
*/
Promise._all = (values) => {
// 判断是否为可迭代对象
if (!values.hasOwnProperty('length')) {
throw new Error(`TypeError: ${typeof values} is not iterable`);
@Teemwu
Teemwu / _render.js
Last active September 15, 2021 01:51
虚拟 DOM 转真实 DOM
'use strict';
const astObj = {
tag: 'DIV',
attrs: {
id: 'app'
},
children: [
{
tag: 'SPAN',
@Teemwu
Teemwu / _setInterval.js
Last active September 14, 2021 10:06
setTimeout 模拟实现 setInterval
'use strict';
/**
* 使用 setTimeout 模拟 setInterval
* @param {Function|string} handler 要执行的函数或者要执行的函数字符串
* @param {number} delay 时间间隔
*/
window._setInterval = function (handler, delay) {
// 判断第二个参数是否为字符串
const isFunc = typeof handler === 'string'
// 获取第二个参数后的其它参数
@Teemwu
Teemwu / _apply.js
Last active September 14, 2021 03:15
手写 apply、call、bind 方法
'use strict';
/**
* 手写 apply 方法
* @param {*} context 上下文 this
* @returns 指定的 this 值和参数
*/
Function.prototype._apply = function (context) {
// 判断上下文 context 是否存在
// 不存在则指向 window
@Teemwu
Teemwu / css3_cube.markdown
Last active April 19, 2020 02:39
css3_cube