/**
 * Diff of two objects.
 * @constructor lib.object.Diff
 * @param {object} older - Older object.
 * @param {object} newer - Newer object.
 * @author Taka Okunishi
 */

var define = require('./_prototype').define;
module.exports = define({
    init: function (older, newer) {
        var s = this;
        var properties = Object.keys(older).concat(Object.keys(newer));
        properties
            .forEach(function (key) {
                var isChanged = older[key] != newer[key];
                s[key] = isChanged ? [older[key], newer[key]] : null;
            });
    },
    /** @lends lib.object.Diff.prototype */
    properties: {
        /**
         * Get new properties.
         * @returns {object}
         */
        newer: function () {
            var s = this,
                result = {};
            Object.keys(s).forEach(function (key) {
                var values = s[key];
                if (values && values.length) {
                    result[key] = values[1];
                }
            });
            return result;
        }
    }
});