【发布时间】:2013-11-21 17:30:00
【问题描述】:
我有一堆 ob 对象,我需要根据用户输入来初始化它们,我所有的对象都基于同一个父对象并且它们以相同的方式初始化。所以现在我有类似的东西:
if (response['type'] === 'texteditor') {
tmpObj = new Texteditor(response['theID'], response['type'], response['devicesView'], templateID);
responseMarkup[0].addEventListener("dblclick", tmpObj);
} else if (response['type'] === 'rectangle') {
tmpObj = new Rectangule(response['theID'], response['type'], response['devicesView'], templateID);
} else if (response['type'] === 'image') {
tmpObj = new MyImage(response['theID'], response['type'], response['devicesView'], templateID);
} else {
tmpObj = new Elements(response['theID'], response['type'], response['devicesView'], templateID);
}
所以因为我将编写更多对象,所以我想做这样的事情:
tmpObj = new $[response['type']](response['theID'], response['type'], response['devicesView'], templateID);
【问题讨论】:
标签: javascript jquery oop