Reputation: 80415
In Flex I can specify a *
as datatype.
What is it and how should I use it.
I've written a inArray()
method that takes as argument something to search for and something to search in. The "something to search for" looks like a great candidate for the *
datatype.
Should I not use it?
Thank you.
Upvotes: 0
Views: 81
Reputation: 15623
The *
actually explicitly says, that something has no type. In fact it's the default type, all untyped variables or functions fall back to.
It basically tells the compiler: "I don't want you to perform any typecheck on this, because this simply gets handled at runtime".
In fact *
is no type. There is simply no value corresponding to it.
Please note, that only expressions of type *
can return the value of undefined
. Anything, that is of type Object
(i.e. anything that is of a different type, than no type), can only hold null
.
You will see that many Array
methods use that type. That's specifically, because Array
elements are of no type and can thus be undefined
.
Therefore, I suppose you could have a slight performance difference based on whether your parameter is typed *
or Object
(or whether you use strict comparison or not, for that matter).
Personally, I would advise you use *
in this case, mostly, because it is consistent with Array
methods.
Upvotes: 2
Reputation: 3011
you have to use * when strict mode of compilation is enabled. It's just 'no type', and it will be checked at runtime.
Upvotes: 1
Reputation: 2483
The * is to AS3 as Object is to Java. See the following:
http://livedocs.adobe.com/flex/3/html/help.html?content=03_Language_and_Syntax_11.html
Upvotes: 2
Reputation: 3031
*
indicates an untyped identifier. You'd use it when you can't guarantee that the type of an object will conform to any specific class or interface definition.
Whether *
is appropriate in your example depends on what operations you use in your search. If you just rely on common equality operations, you should be fine, and in fact it would probably be the best choice.
Upvotes: 2