Skip to content

Instantly share code, notes, and snippets.

@ticky
Created March 24, 2014 00:05
Show Gist options
  • Select an option

  • Save ticky/9731857 to your computer and use it in GitHub Desktop.

Select an option

Save ticky/9731857 to your computer and use it in GitHub Desktop.
"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