Skip to content

Instantly share code, notes, and snippets.

@josher19
Created October 9, 2012 22:46
Show Gist options
  • Save josher19/3861950 to your computer and use it in GitHub Desktop.
Save josher19/3861950 to your computer and use it in GitHub Desktop.
Testing type-of across frames in LiveScript
type-of = (typeof!)
y = type-of([1,2]) #=> 'Array'
x = type-of [1,2] #=> ['Number', 'Number']
iframe = document.createElement('iframe');
iframe.width = 50;
iframe.height= 50;
jQuery(iframe).appendTo(document.body);
iDoc = iframe.contentDocument || iframe.contentWindow.document;
iDoc.write """<script>\
parent.iElement = document.createElement('div');
parent.iArguments = (function(){ return arguments; })(1, 2, 3);
parent.iArray = [1, 2, 3];
parent.iString = 'hello';
parent.iNumber = 100;
parent.iFunction = (function(){});
parent.iDate = new Date();
parent.iRegExp = /hi/;
parent.iNaN = NaN;
parent.iNull = null;
parent.iUndefined = undefined;
</script>"""
iDoc.close();
type-of iArray
iArray instanceof Object
type-of felix
type-of Cat
type-of Dog
type-of iArguments
type-of iNaN
type-of iNull
# typeof! nothing
console.log iArray instanceof Array
console.log iArray instanceof Object
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment