Created
March 24, 2014 00:05
-
-
Save ticky/9731857 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| "use strict"; | |
| /* Create a Constructor with an arbitrary name * | |
| * This allows the resultant object to be of a * | |
| * named "type", allowing inspection of types * | |
| * without adding keys to the object itself */ | |
| function constructorNamed(name) { | |
| return (new Function(["return function ", name, "() {return this;}"].join('')))(); | |
| } | |
| var object = new (constructorNamed("SomeKindOfObject"))(); | |
| console.log(object); | |
| document.body.appendChild(document.createTextNode("Constructor name is \"" + object.constructor.name + "\"")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment