Javascript run() function -


var test = function(msg) {   alert(msg) };  (new test("hi")).run(); (new test("hello")).run(); 

when run above javascript code, able alert "hi". alert "hello" not coming up.

  1. anybody can explain above, new this. know "test" function
  2. what run() method does?, because when removed run in above code, able see both alerts, pls help...

    var test = function(msg) {   alert(msg) };  (new test("hi")); (new test("hello")); 

simple, there no run function, when code runs (new test("hi")).run() runs (new test("hi")) part first, , errors on run second line never executed.

if want call function, call it:

test("hi"); 

don't run functions (that not constructors) constructors. here what new does.


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 -

jquery - javascript onscroll fade same class but with different div -