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

Popular posts from this blog

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -

javascript - Using jquery append to add option values into a select element not working -

javascript - Restarting Supervisor and effect on FlaskSocketIO -