It turns out when you typecast an object as the interface it implements, you lose the fact that it's an object. What up, team ActionScript?
So I've been playing around a lot with type checking, and I was passing objects to a function as their interface, as one is wont to do in an OO world. It turns out, when you type objects as an interface they implement, you lose all reference to the fact that they inherit from the Object class, and consequently you lose the constructor and prototype attributes. The solution, it turns out, is as simple as recasting the instances as Object and away you go, but this seems silly to me. Everything in ActionScript inherits from the Object class, even int and string. Does the interface need to be so strictly enforced that you can't even pull type data?
Seems silly to me.
function getTypeFromInterface(thing:IThing) {
return (thing as Object).constructor;
}
Comments