How can I make a new Window
object, myWindow
, that is independent to window
(so modifying e.g. myWindow.Array.prototype
does not effect window.Array.prototype
), without creating an <iframe>
?
At the moment I'm doing it as follows
function newWindow(){
var myFrame = document.createElement('iframe'), myWindow = undefined;
myFrame.style.display = 'none';
myFrame.src = 'javascript:undefined;';
document.body.appendChild(myFrame);
myWindow = myFrame.contentWindow;
document.body.removeChild(myFrame);
return myWindow;
}
Ultimately, I'd like to make my own copies of core object types and prototype them.
How can I make a new Window
object, myWindow
, that is independent to window
(so modifying e.g. myWindow.Array.prototype
does not effect window.Array.prototype
), without creating an <iframe>
?
At the moment I'm doing it as follows
function newWindow(){
var myFrame = document.createElement('iframe'), myWindow = undefined;
myFrame.style.display = 'none';
myFrame.src = 'javascript:undefined;';
document.body.appendChild(myFrame);
myWindow = myFrame.contentWindow;
document.body.removeChild(myFrame);
return myWindow;
}
Ultimately, I'd like to make my own copies of core object types and prototype them.
Share Improve this question asked Sep 14, 2012 at 0:09 Paul S.Paul S. 66.4k9 gold badges128 silver badges143 bronze badges 1- Related article: How ECMAScript 5 still does not allow to subclass array – Oriol Commented May 4, 2014 at 17:23
2 Answers
Reset to default 3Emm... you can't do that. Well... you may call window.open
, but it will open a new window. And... why do you need that at all? It looks like you are on wrong way.
Depending on what you are doing, a better approach may be to create a normal array, then augment that one particular array instance with the features you need.
function augmentArray(a) {
a.purgeAll = function() {a.length = 0;};
}
var myList = [1, 2, 3];
augmentArray(myList);
myList.purgeAll();
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744759746a4592103.html
评论列表(0条)