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

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

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -