nytimes / backbone.stickit

Backbone data binding, model binding plugin. The real logic-less templates.
MIT License
1.64k stars 176 forks source link

Loss of context in onGet() function #321

Closed noobiek closed 6 years ago

noobiek commented 6 years ago

Hi,

There is an issue with correct context loss in onGet(). "this" begins to point to last item when you do this.stickit() in multiple views with "classes: {}" configured.

The problem is in initializeClasses() and its updateClass() subroutine, where classConfig.view = config.view is defined outside and then used inside updateClass(). Looks like classConfig.view is being "overwritten" in each iteration by next view's .stickit() call.

classConfig is passed to getAttr(), where applyViewFn.call(view, config.onGet, val, config) is done. This results in "this" in onGet() pointing to last "view" passed through initializeClasses().

I fixed this by moving classConfig.view = config.view into updateClass().

If you need further details, please, let me know.

Google Chrome 66.0.3359.139 64bit, if relevant.

Thanks.

noobiek commented 6 years ago

Noone cares, eh? @akre54

akre54 commented 6 years ago

Care to open a pull and then tag me? I'll merge in

noobiek commented 6 years ago

@akre54 Done

noobiek commented 6 years ago

Fixed/tested/merged.