TypeError . .不是构造函数
TypeError ... is not a Constructor
我有以下内容,这是一个解析器函数的开始。它依赖于jQuery扩展。我试图删除jQuery依赖,但当我这样做,我得到'VastParser不是一个构造函数'。我想我需要重新工作如何创建基本对象,使其工作。想法吗?
var VASTParser = $.extend(function(){}, {
constructor: function() {
// only work once...
if (VASTParser._instance) {
this.parse = null;
this.parseVast = null;
throw "VASTParser is a Singlton. Access via getInstance()";
}
VASTParser._instance = this;
console.log("VASTParser instantiated.", "", "VAST");
},
parse: function(xml) {
console.log(xml);
}
});
// create static getInstance()
VASTParser.getInstance = function() {
if (!VASTParser._instance) {
VASTParser._instance = new VASTParser();
}
console.log(VASTParser._instance);
return VASTParser._instance;
};
// call it, to prevent the constructor from being succeeding via direct calls again
VASTParser.getInstance();
根据注释,不需要构造函数,因为它是一个单例对象——
var VASTParser = {
parse: function(xml) {
console.log(xml);
}
};
VASTParser.parse = function(xml) {
return xml;
};
VASTParser.parse({test: 'test xml'});
相关文章:
- ES6构造函数返回基类的实例
- 使用Google Visualization动态调用构造函数
- javascript中对象构造函数中的var属性与this.properties
- 理解typescript中的构造函数接口
- 为什么构造函数不是构造函数
- 未能运行构造函数:TypeError:对象#<对象>没有方法'addPlugin'
- ExtJS5 TypeError:Ext.ux.ProgressBarPager不是构造函数
- 试图使用Shuffle.js,但得到Uncaught TypeError: Shuffle不是构造函数
- 未捕获的TypeError:非法构造函数-在Backbone.JS中使用Bonsai.JS
- TypeError:不是构造函数
- PhantomJS错误:TypeError: undefined不是构造函数(求值'require('s
- Jasmine TypeError: undefined不是构造函数
- TypeError: cognitiveServices.Face不是构造函数
- TypeError . .不是构造函数
- TypeError: & # 39;未定义# 39;不是构造函数(求'new JdRes())
- TypeError: undefined不是构造函数
- 未捕获的TypeError: UnitType不是构造函数
- Google: TypeError: Google .maps. geocoder不是构造函数
- Nodejs:TypeError:对象不是构造函数上的Javascript ES6
- TypeError: google.maps.latLng不是构造函数