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

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -