浏览器事件机制
Vue项目如何优化
Vue MVVM理解及原理实现
TypeScript有什么优势,type和interface的区别
怎样理解闭包
手写节流和防抖函数
原型,class B继承class翻译成es5应该是什么样子
React知识点
-
React 的基本原理
UI = f(state) ,虚拟 DOM、diff 策略、setState -
React事件机制
-
React项目如何优化
-
React的diff
-
redux的重点概念
-
聊一聊React的生命周期
React 生命周期 -
聊一聊 hooks 怎么处理生命周期
笔试题
- JS的链式调用
function Man(name) {
let that = this
this.task = []
let fn = ()=>{
console.log(name)
that.next()
}
this.task.push(fn)
setTimeout(function(){
that.next()
},0)
return this
}
Man.prototype.eat = function(food) {
let that = this
let fn = ()=>{
console.log('eat',food)
that.next()
}
this.task.push(fn)
return this
}
Man.prototype.sleep = function(time) {
let that = this
let fn = ()=>{
setTimeout(function(){
console.log('sleep',time)
that.next()
}, time*1000)
}
this.task.push(fn)
return this
}
Man.prototype.sleepFirst = function(time) {
let that = this
let fn = ()=>{
setTimeout(function(){
console.log('sleepFirst',time)
that.next()
}, time*1000)
}
this.task.unshift(fn)
return this
}
Man.prototype.next = function() {
let fn = this.task.shift()
fn && fn()
}
console.log(new Man('kk').sleep(1).eat('eeee').sleepFirst(5).eat('ddd'))
输出:
sleepFirst 5
kk
sleep 1
eat eeee
eat ddd
- 金额千分位
function change(money) {
let arr = []
let rest = ''
money = String(money)
let index = money.indexOf('.')
if(index !== -1){
rest = money.substring(index)
money = money.substring(0, index)
}
while(money) {
arr.unshift(money%1000)
money = parseInt(money/1000)
}
if(money)
arr.unshift(money)
return arr.join(',') + rest
}
console.log(change(12443456.789))
- 快速排序
function quicksort(arr, l, r) {
if(l >= r)
return
let left = l, right = r, pivot = arr[left]
while(left < right) {
while(left < right && arr[right] >= pivot) right --;
if(left < right) arr[left] = arr[right]
while(left < right && arr[left] <= pivot) left ++;
if(left < right) arr[right] = arr[left]
if(left >= right) arr[left] = pivot
}
quicksort(arr, l, right-1)
quicksort(arr, right+1, r)
return arr
}