Skip to content

Instantly share code, notes, and snippets.

View lilywang711's full-sized avatar
🎯
working

lily wang lilywang711

🎯
working
View GitHub Profile
/*使用伪类 + transform*/
.border_bottom {
overflow: hidden;
position: relative;
border: none!important;
}
.border_bottom:after {
content: ".";
position: absolute;
left: 0;
@lilywang711
lilywang711 / util-functions.js
Last active December 13, 2019 07:00
util functions in vue/packages/vue-template-compiler/build.js
/**
* Define a property.
*/
function def (obj, key, val, enumerable) {
Object.defineProperty(obj, key, {
value: val,
enumerable: !!enumerable,
writable: true,
configurable: true
});
@lilywang711
lilywang711 / prettier-config.json
Created July 5, 2020 07:30
我的 prettier 配置
{
"printWidth": 80,
"semi": true,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "none",
"arrowParens": "avoid"
}
@lilywang711
lilywang711 / override-settimeout.js
Last active July 13, 2020 04:06
重写 window.setTimeout ,收集所有的 timerId,清除页面上所有定时器
function overrideSetTimeout(fn) {
let timerIds = [];
function realSetTimeout(callback, delay) {
const args = Array.prototype.slice.call(arguments, 2)
const timerId = fn(() => {
callback.apply(null, args)
}, delay)
timerIds.push(timerId);
@lilywang711
lilywang711 / umpromisify.ts
Last active July 30, 2020 06:11
反解 promise 类型
type PromiseType<T> = (args: any[]) => Promise<T>;
type UnPromisify<T> = T extends PromiseType<infer U> ? U : never;
// 或者这样一句话: type UnPromisify<T> = T extends (args: any[]) => Promise<infer U> ? U : never;
// 测试 UnPromisify<T>:
async function stringPromise() {
return "string promise";
}
async function numberPromise() {
@lilywang711
lilywang711 / useImperativeHandle.tsx
Created July 30, 2020 06:47
useImperativeHandle in typescript
// 定义
export interface MyInputHandles {
focus(): void;
}
const MyInput: RefForwardingComponent<MyInputHandles, MyInputProps> = (
props,
ref
) => {
const inputRef = useRef<HTMLInputElement>(null);
const pipe = (...fns) => (input) => fns.reduce((acc, fn) => fn(acc), input);
const addOne = (x) => x + 1;
const square = (x) => x * x;
console.log(pipe(addOne, square)(2));
const compose = (...fns) => (input) => fns.reverse().reduce((acc, fn) => fn(acc), input);
const addOne = (x) => x + 1;
const square = (x) => x * x;
console.log(compose(addOne, square)(2));
Array.prototype.customReduce = function (fn, initialValue) {
for (let i = 0; i < this.length; i++) {
// 当未传初始值时取数组中的第一项作为初始值
if (typeof initialValue === "undefined") {
initialValue = fn(this[i], this[i + 1], i, this);
i++;
} else {
initialValue = fn(initialValue, this[i], i, this);
}
}
var type = "window";
const obj = {
type: "obj",
foo(a, b) {
console.log("this.type", this.type, a, b);
}
};
Function.prototype.customCall = function (context, ...restArgs) {