Method object in javascript -
i have written following code , not showing alert.
var test = function(message) { this.show = function() { alert(message) } } (new test("hiii")).show(); (new test("helooo")).show();
when changed following... removed bracket of - (new test("hiii")).show();
it shows both "hiii" , "helooo" alert.
note: did not make changes - (new test("helooo")).show();
var test = function(message) { this.show = function() { alert(message) } } new test("hiii").show(); // was(new test("hiii")).show(); (new test("helooo")).show();
can explain why?
the problem, oddly enough, fact left out semicolon after function expression:
var test = function(message){ this.show = function() { alert(message) } } // <-- missing semicolon
that means ( ... )
following function expression taken argument list function call.
add missing semicolon , first block of code work.
Comments
Post a Comment