Skip to content

Instantly share code, notes, and snippets.

@eligrey
Created October 12, 2011 02:26
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eligrey/1280084 to your computer and use it in GitHub Desktop.
Save eligrey/1280084 to your computer and use it in GitHub Desktop.
Synchronous view creation
/*
* 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;
};
// 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