Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

JavaScript warning - used before defined?

Hi there,

When compiling I get the following message, prob' because I have the functions at the bottom of the JS file:

[WARN] JavaScript compiler reported "'getData' was used before it was defined." at people.js:232

Everything appears to be working and I find it makes code more readable to have functions at the end.

Is there a problem with this approach/do I need to address this?


— asked March 16th 2010 by Chris Reed
  • javascript
  • mobile
  • warnings

2 Answers

  • Accepted Answer

    Pretty sure Ti uses jslint to parse for errors, which is pretty picky.

    I generally keep all of my contained function in a separate file and then include it, before using any of them.

    Don't think your approach will affect your build though

    — answered March 16th 2010 by Nick Lloyd
  • That's a good method Nick - I've been pondering how to organise the code - most functions are data access (running API calls and parsing results). so grouping them into a separate include file could help reuse as well. i.e. I could reference the same include file in multiple contexts and return the result to whichever one was active.

    Marvellous, thanks

    — answered March 16th 2010 by Chris Reed
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.