What should be used while declaring a variable as below:
private var someVar:*;
OR
private var someVar:Object;
What is the difference between the two? What makes one superior then other in various situations? Any examples?
Thanks.
An instance is a specific representation of an object. An object is a generic thing while an instance is a single object that has been created in memory. Usually an instance will have values assigned to it's properties that differentiates it from other instances of the type of object.
A class defines object properties including a valid range of values, and a default value. A class also describes object behavior. An object is a member or an "instance" of a class. An object has a state in which all of its properties have values that you either explicitly define or that are defined by default settings.
A class is a template for creating objects in program whereas the object is an instance of a class. A class is a logical entity while object is a physical entity. A class does not allocate memory space on the other hand object allocates memory space.
An object is simply a collection of data (variables) and methods (functions) that act on those data. Similarly, a class is a blueprint for that object. We can think of a class as a sketch (prototype) of a house. It contains all the details about the floors, doors, windows, etc.
someVar:*
is a special untyped var that holds the default value undefined
while
Object
var default value is null
.
That's the only key difference.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With