Created
October 12, 2011 02:26
-
-
Save eligrey/1280084 to your computer and use it in GitHub Desktop.
Synchronous view creation
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
/* | |
* create-view.js | |
* Easily create new views for accessing clean builtins, etc. | |
* | |
* 2011-10-11 | |
* | |
* By Eli Grey, http://eligrey.com | |
* Public Domain. | |
* NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK. | |
*/ | |
var create_view = function() { | |
"use strict"; | |
var | |
doc = document | |
, doc_el = doc.documentElement | |
, frame = doc.createElementNS("http://www.w3.org/1999/xhtml", "iframe") | |
, id = Math.random() | |
, url | |
, view | |
; | |
frame.name = id; | |
doc_el.appendChild(frame); | |
view = open("about:blank", id); | |
doc_el.removeChild(frame); | |
return view; | |
}; |
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
// example: Object.builtin("Array").prototype.slice instead of Array.prototype.slice, which may be overwritten | |
Object.builtin = function(name) { | |
return create_view()[name]; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment