Typeerror: Cannot Set Property Of Undefined
Here, i am trying to construct object in javascript. But i am getting runtime error as : TypeError: Cannot set property 'functWriteToLogFile' of undefined My javascript object as
Solution 1:
If this
is undefined
, you must be in "strict mode". If you weren't in strict, then this
would be the global object, and you'd have not received the error message, which wouldn't be helpful.
Because the value of this
in a function is defined based on how you invoke the function, and since it seems clear that you intend for this
to reference an that inherits from the .prototype
of the function, you should be invoking the function using new
.
var o = new SetAstAppLog(...my args...);
Given this line of code, you're invoking your module immediately.
varSetAstAppLog = require('astAppLog')(); // <--invoking
This would only be correct if require('astAppLog')
returns a function which would then return a function.
If it simply returns the function that you ultimately want to use, then you need to remove the trailing parens.
varSetAstAppLog = require('astAppLog'); // <-- assigned, not invoked
Post a Comment for "Typeerror: Cannot Set Property Of Undefined"