Skip to content

BC since 0.9.x - Object methods lose context when called #440

@webberig

Description

@webberig

I pass an object to the render function that has a getter method for this template:

The {{ model.getBakedGood() }} is a lie.

The given model has a method getBakedGood that returns this.baked_good from the model object.

This worked fine with twig.js 0.8.9, I've put a working demo in fiddle:
https://jsfiddle.net/mathieumaes/f9px5c63/

I can't seem to get Twig.js 0.9.x and up to work in fiddle, but if you try the given use case in a project, The getter method will return undefined because the context in which the method is called is actually the "root" context of the twig template (aka. { model: Object }, and not the given model object.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions