javascript - TypeError ... is not a Constructor -
i have following, start of parser function. has dependency on jquery extend. trying remove jquery dependency when do, 'vastparser not constructor'. think need rework how create base object make work. thoughts?
var vastparser = $.extend(function(){}, { constructor: function() { // work once... if (vastparser._instance) { this.parse = null; this.parsevast = null; throw "vastparser 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, prevent constructor being succeeding via direct calls again vastparser.getinstance();
per comment, constructor not needed since singleton object --
var vastparser = { parse: function(xml) { console.log(xml); } }; vastparser.parse = function(xml) { return xml; }; vastparser.parse({test: 'test xml'});
Comments
Post a Comment