Interesting AS3 Functionality
17|7|09
I just noticed some interesting functionality in AS3 (although it should work in all languages that support function references). To explain, I'll start with an example
var obj = {r:Math.random()};If we reference this objects' property, we get the same number every time we reference it. But, if we remove the brackets from the 'Math.random()' which instead of referencing the output of the function, references the function itself. So, when we reference the object we reference it like line #2 instead of like line #1.
trace(obj.r)We have to use the brackets on the second version because it is actually a function. So whenever we reference the second type, it gives us a different number every time. Go ahead and try it out with other functions, it will work with any function at all.
trace(obj.r())