This might be a very easy issue. I am still learning javascript and hoping I can get help for the issue below.
var hello = function()
{
this.hey = function()
{
console.log("hey");
}
function init()
{
this.hey();
}
init();
}
var h = new hello();
The above code is complaining the method hey is not defined. But if I do
var h = hello();
It didn't give any issues.
Why is the first one with the new that creates an object gave me error but the second one didn't? I need to create the object, thus I need to use the new keyword. How can I resolve the error I got from first one?