All pastes #97414 Raw Edit

k4st

public javascript v1 · immutable
#97414 ·published 2006-07-23 18:37 UTC
rendered paste body
var TMOChatHistory = {		add: function(message) {		TMOHistoryStack.addMessage(message);	},		get: function() {		TMOHistoryStack.current();	},		reset: function() {		TMOHistoryStack.reset();	}};var TMOHistoryStack = {	history : [],	size : 50,	index : -1,		addMessage : function(message) {		this._trim();		this.history.unshift(new TMOChatMessage(message));	},		current : function() {		this._next();		message = this.history[this.index].getText();				return message;	},		reset : function() {		this.index = -1;	},		_next : function() {		if(this._hasNext()) {			this.index++;		} else {			this.reset();		}	},		_hasNext : function() {		return this.index < this.history.length;	},		_trim : function() {		if(this.history.length == this.size) {			this.history.pop();		}	}};function TMOChatMessage(message) {	this.text = message;}TMOChatMessage.prototype = {		getText : function() {		return this.text;	},		getLength : function() {		return text.length;	}};