Skip to content

Instantly share code, notes, and snippets.

@SimonRichardson
Created April 8, 2013 15:41
Show Gist options
  • Save SimonRichardson/5337775 to your computer and use it in GitHub Desktop.
Save SimonRichardson/5337775 to your computer and use it in GitHub Desktop.
Haxe javascript instanceof improvement.
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