html - Cannot set Property "Something" of undefined. Trouble with JavaScript "strict mode"! -


i having trouble javascript "strict mode". coding library constructor when enable strict mode @ beginning of library so, "use strict"; error - uncaught typeerror: cannot set property 'e' of undefined. following constructor code :-

(function(window, document, undefined){ "use strict";  function ram(cssselector) { //the main constructor of library     if (this === window) { return new ram(cssselector); }      if ((cssselector !== undefined) && (typeof cssselector === "string")) {         this.e = catchel(cssselector);     } else {         this.e = cssselector;     }     this.csssel = cssselector; }  }(this, this.document)); 

thanks @dave, able fix issue in following way:-

function ram(cssselector) { //the main constructor of library     if (this === window) { return new ram(cssselector); }      //this code helps call constructor without new keyword!     //thanks dave help!     if (this instanceof ram) {         this.e = ((cssselector !== undef) && (typeof cssselector === "string")) ? catchel(cssselector) : cssselector;         this.csssel = cssselector;     } else {         return new ram(cssselector);     } } 


Comments

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -