Let’s think about the function signature in different (statically typed) languages. Remember, the compile breaks out of the function when return method is called, and nothing after it is run. The function defines a return type, and to a naive programmer looking at the signature it seems that one can only return a single thing. And it’s true- you can only return one thing. But, that thing can be an Object or an Array.
This tip works for many languages, and it’s not explicitly stated all the time when starting out. I had already known that you could do this, but kudos to the book “Javascript & JQuery” by Jon Duckett for inspiring me to write a post about it. It’s a very colorful and friendly book that is actually read fun to read which is a huge accomplishment for a book about programming. Anyway, this is a useful little tip to remember when crafting your functions.
Let’s think about the function signature in different (statically typed) languages. Remember, the compile breaks out of the function when return method is called, and nothing after it is run. The function defines a return type, and to a naive programmer looking at the signature it seems that one can only return a single thing. And it’s true- you can only return one thing. But, that thing can be an Object or an Array.
0 Comments
This is a really cool, simple method for sketching out what you want your code to do. I came across this flowcharting method from page 23 of the great book “Javascript and JQuery” by Jon Duckett (screenshots below). He describes the motivation for them like this:
“Often scripts will need to perform different tasks in different situation. You can use flowcharts to work out how the task fit together. The flowcharts show the paths between in step.” Link to the original video: https://devchat.tv/adventures-in-angular/001-aia-the-birth-of-angular-1 This is the very first podcast in a long series of Angular podcasts. I’m just getting into them now myself, but I liked this first one a lot and wanted to share it in a blog post.
This has happened to me enough times before for me to be embarrassed by it, and for that reason I'm writing this blog post about it. If you have an if statement that is always returning true (it feels something like, "GAAAHH, why does my if statement always return true!) then this could be your problem (and solution!). I noticed this mistake again today working in Actionscript 3 while fixing a bug in Head Exploder. Here's a simplified version of the as3 code:
var smallNumber:Number = 1; var bigNumber:Number = 100; if (smallNumber > bigNumber) { trace("Uh oh!"); }
In the world today users will take for granted the ability to use the tab key on the keyboard to navigate between text fields in a form. In Flash you are building dialog boxes from shapes and TextFields so it can't guess how you want the tabs to be controlled. Luckily, you are given total control over this because text fields have the properties tabIndex and tabEnabled.
Tab index – This is an integer that basically allows you to put this text field in a list relative to all the other fields. The first one we should have a tabIndex of one, the second tabIndex of two, and so on. So suppose now you have the text field with tab index of one selected (which for TextFields just means that there is a cursor blinking inside of it). Then pressing tab will move your cursor to the TextField with index two. If you press tab again when the selection is on the text field the highest index then the list will loop back around, and the one that has index one will be selected. |
AuthorThe posts on this site are written and maintained by Jim Lynch. About Jim...
Categories
All
Archives
March 2023
|