oop - create new javascript object from variable -


i create new object in javascript (using simple inheritance) such class of object defined variable:

var class = 'person'; var inst = new class 

any ideas?

you can like

function person(){}; var name = 'person'; var inst = new this[name] 

the key referencing object owns function that's constructor. works fine in global scope if you're dumping code inside of function, might have change reference because this wont work.

edit: pass parameters:

function person(name){alert(name)}; var name = 'person'; var inst = new this[name]('john') 

Comments