原型

使用 class,避免直接操作 prototype

// bad
function Queue(content = []){
  this._queue = [...content]
}
Queue.prototype.pop = function (){
  const value = this._queue[0]
  this._queue.splice(0, 1)
  return value
}

// good
class Queue {
  constructor (content = []){
    this._queue = [...content]
  }
  pop (){
    const value = this._queue[0]
    this._queue.splice(0, 1)
    return value
  }
}

results matching ""

    No results matching ""