mirror of
https://github.com/airbnb/javascript.git
synced 2026-01-14 05:08:25 -05:00
14
README.md
14
README.md
@@ -890,23 +890,23 @@ Other Style Guides
|
||||
```javascript
|
||||
// bad
|
||||
function Queue(contents = []) {
|
||||
this._queue = [...contents];
|
||||
this.queue = [...contents];
|
||||
}
|
||||
Queue.prototype.pop = function () {
|
||||
const value = this._queue[0];
|
||||
this._queue.splice(0, 1);
|
||||
const value = this.queue[0];
|
||||
this.queue.splice(0, 1);
|
||||
return value;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// good
|
||||
class Queue {
|
||||
constructor(contents = []) {
|
||||
this._queue = [...contents];
|
||||
this.queue = [...contents];
|
||||
}
|
||||
pop() {
|
||||
const value = this._queue[0];
|
||||
this._queue.splice(0, 1);
|
||||
const value = this.queue[0];
|
||||
this.queue.splice(0, 1);
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user