Note that there are some explanatory texts on larger screens.

plurals
  1. POdust.js losing 'this' context in handlers?
    text
    copied!<p>I have a [seemingly] trivial dust.js template. The context object I am using to render the template contains a handler which references another item in the context object. I also include a toString handler, which also references another item in the context object.</p> <p>Template:</p> <pre><code>{error} &lt;pre&gt; {#error.getStackTrace} {.}{~n} {/error.getStackTrace} &lt;/pre&gt; </code></pre> <p>Context:</p> <pre><code>{ error: { st: ['a','b','c'], msg: 'This is an error message', getStackTrace: function () { return this.st; }, toString: function () { return this.msg; } } } </code></pre> <p>Rendered:</p> <pre><code>This is an error message&lt;pre&gt;&lt;/pre&gt; </code></pre> <p>If I reference <code>{#error.st}</code> directly, it renders correctly:</p> <pre><code>This is an error message&lt;pre&gt;a b c &lt;/pre&gt; </code></pre> <p>If I inspect 'this' inside of the getStackTrace() handler, it is pointing back to DOMWindow. It is interesting, however, that invoking toString() implicitly, it is scoped correctly. If I explicitly invoke toString() <code>{error.toString}</code>, then the scope jumps back to DOMWindow.</p> <p>The only reason this is a problem, (why I cannot access <code>error.st</code> directly) is because the st array is actually stored in a Qooxdoo property, and I only have access to the generated getter. The above example mimics the actual object as simply as I can.</p> <p>Is this a bug in dust.js? Is it losing the correct scope in handlers? Or am I missing something in the dust.js docs to retain scope?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload