Created
April 8, 2013 15:41
-
-
Save SimonRichardson/5337775 to your computer and use it in GitHub Desktop.
Haxe javascript instanceof improvement.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
js.Boot.__instanceof = function(o,cl) { | |
if (o === null || cl === null) return false; | |
if (typeof cl === 'function') { | |
if(o instanceof cl) { | |
if(cl == Array) return o.__enum__ == null; | |
return true; | |
} | |
if(js.Boot.__interfLoop(o.__class__,cl)) return true; | |
} | |
switch(cl) { | |
case Int: | |
return Math.ceil(o%2147483648.0) === o; | |
case Float: | |
return typeof(o) == "number"; | |
case Bool: | |
return o === true || o === false; | |
case String: | |
return typeof(o) == "string"; | |
case Dynamic: | |
return true; | |
default: | |
if(o == null) return false; | |
if(cl == Class && o.__name__ != null) return true; else null; | |
if(cl == Enum && o.__ename__ != null) return true; else null; | |
return o.__enum__ == cl; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment