Skip to content

Private Variables dont match the Instance #31

@macedd

Description

@macedd

Consider the following classes

    var CrudPage = P(function(crud)
    {
        var self = crud;
        crud.container = '#none';

        crud.init = function() {
            self = this;

            $(document)
                .on('click', function()
                {
                    alert(self.container);
                });
        }
    }
    var UserPage = P(CrudPage, function(user, crud)
    {
        movimentacao.container = '#user';
    });
    var ProductPage = P(CrudPage, function(product, crud)
    {
        movimentacao.container = '#product';
    });

All fine. Loved the implementation.

Lets go to the problem, thats occours on instantiation

# we create the instances
var user = UserPage();
var product = ProductPage();

# and trigger our test click
$(document).trigger('click');

The private self, used to reference the Class out of the this scope, got overwritten by each instance. So the events don't know UserPage anymore.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions