From e677b4c6418a587816f7017dd29517ff210e102f Mon Sep 17 00:00:00 2001 From: Robert Kolner Date: Wed, 28 Nov 2012 22:26:28 +0100 Subject: [PATCH] See ya, eval. --- index.html | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/index.html b/index.html index 4caf3e0..95d3e7a 100644 --- a/index.html +++ b/index.html @@ -37,6 +37,17 @@ console.error('Failed to load ' +filename); } } + + function instantiate(className, args) { + var o, f, c; + c = window[className]; // get reference to class constructor function + f = function(){}; // dummy function + f.prototype = c.prototype; // reference same prototype + o = new f(); // instantiate dummy function to copy prototype properties + c.apply(o, args); // call class constructor, supplying new object as context + o.constructor = c; // assign correct constructor (not f) + return o; + } var QueryString = function () { // This function is anonymous, is executed immediately and @@ -71,9 +82,9 @@