Phaser.LinkedList = function (){ this.next = null ; this.prev = null ; this.first = null ; this.last = null ; this.total = 0; } ; Phaser.LinkedList.prototype = { add: function (item){ if (this.total === 0 && this.first === null && this.last === null ) { this.first = item; this.last = item; this.next = item; item.prev = this; this.total++ ; return item; } this.last.next = item; item.prev = this.last; this.last = item; this.total++ ; return item; } , reset: function (){ this.first = null ; this.last = null ; this.next = null ; this.prev = null ; this.total = 0; } , remove: function (item){ if (this.total === 1) { this.reset(); item.next = item.prev = null ; return ; } if (item === this.first) { this.first = this.first.next; } else if (item === this.last) { this.last = this.last.prev; } if (item.prev) { item.prev.next = item.next; } if (item.next) { item.next.prev = item.prev; } item.next = item.prev = null ; if (this.first === null ) { this.last = null ; } this.total-- ; } , callAll: function (callback){ if (!this.first || !this.last) { return ; } var entity = this.first; do { if (entity && entity[callback]) { entity[callback].call(entity); } entity = entity.next; } while(entity != this.last.next)} } ; Phaser.LinkedList.prototype.constructor = Phaser.LinkedList;