Titanium JIRA Archive
Alloy (ALOY)

[ALOY-969] Variable position in compiled alloy file

GitHub Issuen/a
TypeBug
PriorityLow
StatusClosed
ResolutionInvalid
Resolution Date2014-03-13T13:22:06.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsRuntime
Labelscompiler, js
ReporterGuile
AssigneeTim Poulsen
Created2014-03-12T10:30:37.000+0000
Updated2018-03-07T22:28:25.000+0000

Description

I declare a button with a onClick event that uses a function.

Attachments

FileDateSize
index.js2014-03-12T10:30:37.000+0000204
index.js2014-03-12T10:30:37.000+00001666
index.xml2014-03-12T10:30:37.000+0000285

Comments

  1. Tim Poulsen 2014-03-13

    You're not taking into account JavaScript's [variable hoisting](http://www.kenneth-truyers.net/2013/04/20/javascript-hoisting-explained/). Rather than using a function statement, use a function declaration.
       function myFunc() {
         // this whole function, including its contents will be hoisted to the
         // top of the enclosing scope, as if you declared it before other variables
         // this is called a function declaration
       }
       
       var myFunc = function() {}; // is treated as if you wrote it this way:
       
       var myFunc;
       // the rest of your variable declarations and other code comes here
       // then the assignment of your function to the myFunc variable
       myFunc = function() {};
       
       var myFunc = function() {}; // is called a function statement
       
  2. Tim Poulsen 2014-03-13

    JavaScript hoisting issue, not Alloy problem
  3. Guile 2014-03-14

    Thank you Tim! :-) I am aware of this and found the solution by using a function declaration (I didn't know all of the terms you said) I still don't know how I can use a _.throttle(function () {}) event then (by example).
  4. Tim Poulsen 2014-03-14

    We're getting a bit off topic here and Jira isn't really for help conversations. That said, check the Underscore docs http://underscorejs.org/#throttle or perhaps http://drupalmotion.com/article/debounce-and-throttle-visual-explanation If you're still stuck, ask in the Q&A forums please.
  5. Eric Merriman 2018-03-07

    Closing as invalid. If this is incorrect, please reopen.

JSON Source