Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #18359

Re: handlebars javascript error on return in function, i is not defined

Path csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder2-2.proxad.net!npeer.de.kpn-eurorings.net!npeer-ng0.de.kpn-eurorings.net!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail
Content-Type text/plain; charset="UTF-8"
Message-ID <9385853.fL9pMimAyI@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Reply-To Thomas 'PointedEars' Lahn <usenet@PointedEars.de>
Organization PointedEars Software (PES)
Date Wed, 06 Feb 2013 04:15:16 +0100
User-Agent KNode/4.8.5
Content-Transfer-Encoding 8Bit
X-Face %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&.<b';Md8`dH6iqhT)6C^.Px|[=M@7=Ik[_w<%n1Up"LPQNu2m8|L!/3iby{-]A+#YE}Kl{Cw$\U!kD%K}\2jz"QQP6Uqr],./"?;=4v
Face iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEXTxa4RFk5dUWANED8PFEfy7+MGBiW+n3ZNF/QuAAACaElEQVQ4jVXUwVOcMBQG8Dc7Rc4PUntdWV2uxjDpGaGeozOp1woar4jd5t/v9wLstMwsA/ntlxdCAgUc1hjTc9/JCZfGoo3wG3HdmdAWrIJRHe7GM/TmpY5VFefuVcAkkPbLIaN8rmPmjloyZxgyR3GuJ4K0AGtJ2htz8o7yqikm759fldQXaMpbDzjKAG+8v+AugVTOPO5DOjLvGtUYQwh0CPjnVMyGd+8/GfUB5nLKJDD2aLDh5HYyMDJGDwQIo2ZmZcKbowNmAdB/AzyFhrmF2MHRb0QJJfaAnwGB6orZhoykLzJtGwF/xpYxI1dswomiUj3gTuAIqCn/4C7cULwGNBtwMTk3Y4LfKB5YUaOKBKYtpplm7u0vip8tU1NWWyI/7XdcSuIDoMt6rVHMWT0DbjHPGqDqZVSa6zleLcUTcIKLoMv3ueJluALtAo9B302zPPlrtiVScRdCjXvVh3e3JpYa/jjkuC9N+LrBMlz/eAN4eQijX2EdLo6c5tGGHwLyHFtXk89dDGHwCVhG9T0S/j55AhRZgkMCmUQXJ49TnS1wnQDvw0eAh9ICeMmEFbCnPMFzjAvsWoEWEFdYEx+S0MoUZ1gT1wId8+AF3Bl2OoEu906AUHx5VLw/gXYg/x84loOah/2UYNrgiwSwGO7RfUzVBbx/kgpckumGOi6QirtD6gkLTitbnxNol47S2jVc2vsN5kPqaAHT8uUdAJM4v/DanjYOwmUjWznGfwB7sGtAtor5BgofDuzaRj4kSQAqDakTsKORa3Q3xKi3gE1fhl71KRMqrdZ2AWNNg/YOhQyrVBnb+i+nEg4bsDA+egAAAABJRU5ErkJggg==
Subject Re: handlebars javascript error on return in function, i is not defined
Newsgroups comp.lang.javascript
References <ab80af3d-ae71-455f-a5de-e9e67a0ba2f9@googlegroups.com>
MIME-Version 1.0
Lines 73
NNTP-Posting-Date 06 Feb 2013 04:15:17 CET
NNTP-Posting-Host 877cecf1.newsspool3.arcor-online.net
X-Trace DXC=oG2`23\EbSOI7\_^6>c20JMcF=Q^Z^V3H4Fo<]lROoRA8kF<OcfhCOKkVJJEDc\6YFDZm8W4\YJNLb@mF9jNikdE3>YBYU3JEoMV[9Gnc^kegO
X-Complaints-To usenet-abuse@arcor.de
Xref csiph.com comp.lang.javascript:18359

Show key headers only | View raw


Not usually reading Googlodytes, but FWIW …

jr wrote:

> I want to print a simple list using a js template in this order:

There is no such thing as a “js template”.  There is no single “js” language 
to begin with.

> User, product list, benefit list, status.
> I get a reference error on the value returned.
> ReferenceError: i is not defined
> 
> 
> I can tell what the problem is but I don't know how to solve it.
> I need to use the {{#each}}{{/each}} function to count the number of
> products and benefits. I just want to add the count of i on each, {{each}}
> block to the returned options and context . I am not sure what this line
> returns but I dont' need the values returned just the count.
>  ret = ret +  options.fn(context[i]);
> <html>
> <head>
> <script type="text/javascript"
> src="js/vendor/handlebars-1.0.rc.1.js"></script> <script
> type="text/x-handlebars-template">

“text/x-handlebars-template” is not a registered MIME media type.  If it 
works at all in a user agent then the scripting language used is, at best, a 
very distant relative of ECMAScript and therefore very probably off-topic 
here.

<http://www.w3.org/TR/2012/CR-
html5-20121217/scripting-1.html#scriptingLanguages>

> […] Handlebars.registerHelper('each', function(context, options) {
>   var ret = "";
> 
>   for(var i=0, j=context.length; i<j; i++) {
>     ret = ret +  options.fn(context[i]);
>     product:i;
>     benefit:i;

In a conforming implementation of ECMAScript without syntax extensions that 
would be two /LabelledStatement/s where each evaluates to the value of ”i” 
without further effect.  In the “text/x-handlebars-template” scripting 
language, however, it may mean anything.

>   }
> 
>   return {ret, product:i, benefit:i};

There is no telling (without RTFM, which you should have done) how this 
rather obscure scripting language works.  For example, it is possible that, 
contrary to strict implementations of ECMAScript Ed. 5.x, it uses block 
scoping which would cause “i” to be unavailable outside of the loop because 
it was declared inside of it.  Which explain the ReferenceError exception.

On the other hand, you may have simply made a copy-and-paste error again.

You have a long record on Usenet to be challenged by even the simplest 
programming tasks.  I wonder, why are you repeatedly and continuously 
choosing the most obscure tools (here: *handlebars* *Release Candidate* 1) 
to achieve what you want?  Why not finally learn this craft from the ground 
up, starting with simple standards-compliant code that you have actually 
written yourself?

<https://developer.mozilla.org/en-US/docs/>

-- 
PointedEars

Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

handlebars javascript error on return in function, i is not defined jr <jlrough@yahoo.com> - 2013-02-05 15:05 -0800
  Re: handlebars javascript error on return in function, i is not defined Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-02-06 04:15 +0100
  Re: handlebars javascript error on return in function, i is not defined JRough <janis.rough@gmail.com> - 2013-02-06 10:24 -0800
    Re: handlebars javascript error on return in function, i is not defined Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-02-07 00:27 +0100

csiph-web