这是我为准备前端/全栈开发工程师面试整理的第27天每日三题练习,涵盖了:
选择器类型 | 权重值 | 示例 |
---|---|---|
行内样式 | 1000 |
|
ID选择器 | 100 | #header |
类/伪类/属性选择器 | 10 | .active, :hover |
元素/伪元素选择器 | 1 | div, ::before |
通配符/继承样式 | 0 | *, 继承的font-size |
/* 权重计算:1(id) + 1(class) + 1(element) = 100+10+1=111 */
#nav .item li { color: blue; }
/* 权重计算:2(class) + 1(element) = 10*2+1=21 */
.list.item span { color: red; }
.title { color: black !important; }
@NgModule({
providers: [
{ provide: Logger, useClass: FileLogger } // 接口映射实现
]
})
constructor(
@Optional() private config: AppConfig,
@Inject('API_URL') private apiUrl: string
) {}
{
provide: DataService,
useFactory: (http: HttpClient) => {
return environment.production
? new ProdDataService(http)
: new MockDataService();
},
deps: [HttpClient]
}
核心技术方案:
实时同步机制
// 客户端发送操作
{
type: 'insert',
position: 15,
text: 'Hello',
version: 42 // 当前文档版本
}
冲突解决策略
服务端版本校验
客户端操作重放(自动合并冲突)
通信协议优化
// WebSocket消息格式
{
"type": "text-update",
"clientId": "abc123",
"changes": [
{ "pos": 10, "text": "新增内容" }
],
"timestamp": 1629876543210
}
前端关键技术点:
架构设计
关键技术点
光标位置同步
// 实时显示他人光标
document.addEventListener('selectionchange', () => {
const selection = window.getSelection();
socket.emit('cursor-update', {
position: selection.anchorOffset
});
});
变化节流处理
// 使用RxJS进行输入防抖
textInput$.pipe(
auditTime(300), // 300ms收集一次变化
distinctUntilChanged()
).subscribe(sendToServer);
版本控制
class DocumentModel {
constructor() {
this.version = 0; // 当前版本号
this.pendingOps = []; // 待确认操作队列
}
}
性能优化
坚持每日三题,未来更进一步!如果你也在准备面试,欢迎一起刷题打卡!