Skip to content
This repository was archived by the owner on Mar 20, 2021. It is now read-only.

Cannot access this inside itemView function in CollectionView #365

Open
marek-baranowski opened this issue May 7, 2014 · 3 comments
Open
Milestone

Comments

@marek-baranowski
Copy link

Thorax.CollectionView.extend({
        collection: new NotesCollection(),
        itemView: function(item) {
            console.log(this);
            return new NoteView({
                model: item.model
            });
        }
    });

Why console.log(this) shows Thorax.CollectionView.extend.itemView {} instead of object? This is problematic for me because I need to access objects attributes inside this function. It only happens in itemView function.

@kpdecker
Copy link
Contributor

This is certainly unexpected. Could you PR a failing test for this?

@finpingvin
Copy link

I became curious of this, and dove through the source.
Are you really meant to be able to use both factory-functions that return an itemView-instance and assign itemView-classes directly on the attribute?

Currently it seems like the code simply accepts the value as a viewclass if it is a function:
https://github.com/walmartlabs/thorax/blob/master/src/util.js#L249

Wouldn't it be hard to differentiate a factory-function from a Backbone class, since a Backbone class is a function itself?

If you could use a factory-function for itemView it would be useful for me as well :)
Then I would be in more control of what arguments are passed to the itemView-instance.

@kpdecker kpdecker added this to the 3.0 milestone Nov 30, 2014
@jasonwebster
Copy link

I can confirm that this is the case, and kind of a pain. I'll take a crack at a PR w/ test cases.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

4 participants