# es5杂七杂八的题
# 面向对象
function Car(){}
function BMW(){}
BMW.call(Car)
BMW.prototype=Object.creat(Car)
BWM.prototype.constructor = BWM
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
# 深考buffer
const allocUnsafe = Buffer?Buffer.allocUnsafe:undefined;//判断是否有buffer
function cloneBuffer(buffer,isDeep){
if(!isDeep){
return buffer.slice()
}
const length = buffer.length()
const result = allocUnsafe?allocUnsafe(length):new buffer.constructor(length);
buffer.copy(result)
return result
}
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11