2017笔试题目

第一题:面向对象思想的测评

class Cash{
    //code here
}

实现的功能:
const cash1 = new Cash(105);
const cash2 = new Cash(66);

const cash3 = cash1.add(cash2);
const cash4 = Cash.add(cash1,cash2);
const cash5 = Cash.add(cash1 + cash2);

console.log(`${cash3}`,`${cash3}`,`${cash3}`);

输出结果如下:

1元7角1分 1元7角1分 1元7角1分

第二题,实现一种事件机制

class EventEmitter{
    //code here
}

const eventMitter = new EventEmitter();
eventMitter.on("foo",hander)

on:添加事件,可以添加多个事件,并且可以多次触发。
once:添加一个事件,出发一次之后就不再触发
fire:触发这个事件,触发一次之后就不会再触发
off:移除一个事件

第三题,主观题:

产品上线了,但是用户体验很受ajax请求影响,现在要求统计所有ajax请求的时间。

因为在做题忘记记下题目,所以题目有点模拟两可,但是还是记下来,求思路。

阅读 3.4k
4 个回答

我居然没有去报名TAT

class Cash{
    constructor(money){
        this.money = money;
    }
    change(value){
        var moneylist = ['元','角','分']
        switch(value.toString().length){
            case 0:
                return 0;
            case 1:
                return value+'分';
            case 2:
                return value.toString().slice(0,1)+'角'+value.toString().slice(1)+'分'
            case 3:
                return value.toString().slice(0,1)+'元'+value.toString().slice(1,2)+'角'+value.toString().slice(2)+'分'
            default:
                return ''
        }
    }
    add (arg){
            this.money = this.money + arg['money']
            return this
    }
    valueOf(){
        return this.money
    }
    toString(){
        
        return this.change(this.money)
    }
}
Cash.add = function (...arg){
        let money = arg.reduce((a,b)=>{return a+b})
        return new Cash(money)
};

const cash1 = new Cash(105);
const cash2 = new Cash(66);

const cash3 = cash1.add(cash2);
const cash4 = Cash.add(cash1,cash2);
const cash5 = Cash.add(cash1 + cash2);
console.log(`${cash3}`,`${cash3}`,`${cash3}`);

第二个起两个数组保存事件集对象就可以了吧。。。。
第三个用断点方式在发送至成功之后收集时间。。应该可以了吧

我居然没报名!!!

有其它更好的答案了

第一题与“面向对象”有毛关系 ……

产品上线了,但是用户体验很受ajax请求影响,现在要求统计所有ajax请求的时间。

F12 ^o^

class Cash{
  constructor(num) {
    this.num = num
  }
  
  add(...args) {
    if (args.length === 1) {
      if (typeof args[0] === 'number') {
        const num = (this.num || 0) + args[0]
      
        return `${parseInt(num / 100)}元${parseInt(num / 10) % 10}角${num % 10}分`
      }
      
      if (typeof args[0] === 'object' && args[0] instanceof Cash) {
        const num = this.num + args[0].num
      
        return `${parseInt(num / 100)}元${parseInt(num / 10) % 10}角${num % 10}分`
      }
    }
    
    if (args.length > 1) {
      let num = 0
      
      args.forEach(item => num += item)
      
      return `${parseInt(num / 100)}元${parseInt(num / 10) % 10}角${num % 10}分`
    }
  }
  
  static add(...args) {
    if (args.length === 1) {
      if (typeof args[0] === 'number') {
        const num = (this.num || 0) + args[0]
      
        return `${parseInt(num / 100)}元${parseInt(num / 10) % 10}角${num % 10}分`
      }
      
      if (typeof args[0] === 'object' && args[0] instanceof Cash) {
        const num = this.num + args[0].num
      
        return `${parseInt(num / 100)}元${parseInt(num / 10) % 10}角${num % 10}分`
      }
    }
    
    if (args.length > 1) {
      let num = 0
      
      args.forEach(item => num += item)
      
      return `${parseInt(num / 100)}元${parseInt(num / 10) % 10}角${num % 10}分`
    }
  }
  
  toString() {
    return this.num
  }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题