Source: History.js

(function() {
    /**
     * @typedef {Object} Help4.History.Params
     * @property {Array<*>} [data = []]
     */

    /**
     * History handler.
     * @augments Help4.jscore.Base
     */
    Help4.History = class extends Help4.jscore.Base {
        /**
         * @override
         * @param {Help4.History.Params} params
         */
        constructor({data}) {
            super({
                statics: {
                    _data: {init: data || [], destroy: false}
                }
            });
        }

        /** @returns {Help4.History} */
        clean() {
            this._data = [];
            return this;
        }

        /** @returns {number} */
        count() {
            return this._data.length;
        }

        /**
         * @param {*} item
         * @returns {Help4.History}
         */
        push(item) {
            this._data.unshift(item);
            return this;
        }

        /** @returns {Help4.History} */
        pop() {
            this._data.shift();
            return this;
        }

        /** @returns {*} */
        last() {
            return this._data[0];
        }

        /** @returns {*} */
        forelast() {
            return this._data[1];
        }

        /** @returns {string} */
        serialize() {
            return Help4.JSON.stringify({data: this._data});
        }

        /**
         * @param {string} data
         * @returns {Help4.History}
         */
        deserialize(data) {
            this._data = Help4.JSON.parse(data).data;
            return this;
        }
    }
})();