局中

fiddle在线编码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
.parent{
position: relative;
height: 300px;
}
.child{
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto;
width: 100px; // 必须要写宽高
height: 100px;
}

或者

1
2
3
4
5
6
7
8
9
10
.parent{
position: relative;
height: 300px;
}
.child{
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}

模拟new,创建一个对象并设置原型,调用constructor,并根据返回值判断返回什么

1
2
3
4
5
function createInstance(constructor, ...args){
const obj = Object.create(constructor.prototype)
const result = constructor.apply(obj, args)
return (result && typeof result === 'object') ? result : obj;
}

如果你想完成整个冲突处理流程,通常要做:

git checkout –theirs pnpm-lock.yaml # 选择使用 “theirs” 版本
git add pnpm-lock.yaml # 标记为已解决
git commit # 完成合并提交(如果是手动合并)

命令 作用
git checkout --ours FILE 使用当前分支的版本解决冲突
git checkout --theirs FILE 使用合并进来分支的版本解决冲突
git add FILE 标记冲突已解决
git commit 完成合并

在shell中查看pnpm-lock.yaml的前10行

head -n 10 pnpm-lock.yaml

配合 cat -n 给每行加上行号再显示前 10 行:
cat -n pnpm-lock.yaml | head -n 10

用function实现继承

1
2
3
4
function extend(sub, par){
sub.prototype = Object.create(par.prototype);
sub.prototype.constructor = sub;
}