1.手写题
var data = [
{price: 8, name:'A-asd'},
{price: 4, name:'A-111'},
{price: 9, name:'A-222'},
{price: 10, name:'B-222'},
]
find(data).where({name: /^A/}).orderBy('price', 'Desc')
实现find方法的链式调用where及orderBy
function find(data){
return data;
}
Array.prototype.where = function(obj) {
const reg = obj.name;
return this.filter(item => reg.test(item.name));
}
Array.prototype.orderBy = function(name, desc){
const isDesc = desc == 'Desc';
return this.sort((a,b) => {
if (isDesc) return b[name] - a[name];
return a[name] - b[name];
})
}
望大佬们指点
2.技术面试
- 原型、原型链
- this指向
- 用es5实现class
- 继承
- 断点续传