Ben
Ben

Reputation: 62404

Variable Scope: cross-class function call

I have a vehicle and a product object and I need vehicle to call a function within product.... I can't seem to figure it out, what should I do here?

var vehicle = function () {
    return {
        init: function () {
            var that = this;

            jQuery('.vehicle-year-profile .options .delete').bind('click', function (e) {
                e.preventDefault();
                that.remove(jQuery(e.currentTarget).parents('.vehicle-year-profile'));
            });

            jQuery('.vehicle-year-profile .options .edit').bind('click', function (e) {
                e.preventDefault();
                that.edit(jQuery(e.currentTarget).parents('.vehicle-year-profile').attr('id'));
            });

            jQuery('#association-detail .save').bind('click', function (e) {
                e.preventDefault();
                that.save();
            });
        },
        edit: function (id) {},
        save: function () {},
        remove: function (el) {},
        reset: function () {}
    }
}();

var product = function () {
    return {
        refreshHistory: function () {}
    };
}();

Upvotes: 2

Views: 212

Answers (1)

Pointy
Pointy

Reputation: 413757

Have you tried

product.refreshHistory();

?? The variable "product" is global (or at least relatively global), so code inside the "vehicle" object can refer to it directly.

Upvotes: 2

Related Questions