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

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 -