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
Post a Comment