handlebars-lang / handlebars-lang/handlebars.js
functions in nested objects are not bound to that object, resulting in inconsistent behavior
- Dominant language
- JavaScript
- Stars
- 18.7k
- Forks
- 2.1k
- PR merge metrics
- No merged PRs in 30d
Description
Given the following input:
``` javascript
const context = {
nested: {
awesome: function () {
return this.more;
},
more: 'Deeply awesome'
},
more: 'More awesome'
}
```
the following template:
``` handlebars
{{nested.awesome}}
```
yields `'More awesome'`, whereas the equivalent Javascript:
``` javascript
context.nested.awesome()
```
yields `'Deeply awesome'`
More importantly,
```
{{#with nested}}
{{awesome}}
{{/with}}
```
also yields `'Deeply awesome'`.
Here is the [js-fiddle demonstrating this](https://jsfiddle.net/02rxztk5/)
PR submitted with a failing test case: #1861.
Contributor guide
Research direction
Start with the nested-object examples in the issue and the failing test case submitted in PR #1861. Reproduce the difference between {{nested.awesome}} and the #with form, then confirm that direct property access binds the function to the nested object and returns 'Deeply awesome'.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100