![](/img/trans.png)
[英]Uncaught TypeError: undefined is not a function while creating a subview using backbone
[英]Uncaught TypeError: undefined is not a function while creating the object using variable
你没有按预期获得对象。 您的代码在窗口对象上查找名称为fabric.Circle
的属性,而不是您想要window.fabric
对象的Circle
属性。 您可以使用以下代码执行此操作:
var object='fabric.Circle',
objects={};
objects['test1']=new getObj(object)();
function getObj(path) {
path = path.split('.');
var obj = window;
while (path.length) {
obj = obj[path.shift()];
}
return obj;
}
您必须解析object
。
在这里演示: http : //jsfiddle.net/L4WyP/
function getProp(prop) {
var parts = prop.split('.');
var obj = window;
do {
obj = obj[parts.shift()];
} while (parts.length);
return obj;
}
var object = 'fabric.Circle',
objects = {};
objects['test1'] = new (getProp(object))();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.