javascript - How to call a method from within a constructor -


i've searched question mine, hasn't been helpful because seems asking (and answering) bit more advanced query (i'm @ bottom level of javascript knowledge/skills).

here code:

function xypoint(x, y){     this.x = x;     this.y = y;     this.debugmessage = function(){         document.getelementbyid("messagearea").innerhtml =                 "xypoint(x, y) constructor called";     }; } 

i want informative message print automatically when do

var mypoint = new xypoint(10, 20); 

i don't want have execute 2 statements this:

var mypoint = new xypoint(10, 20); mypoint.debugmessage(); 

any appreciated. thanks.

just call debugmessage in constructor:

function xypoint(x, y){     this.x = x;     this.y = y;     this.debugmessage = function(){         document.getelementbyid("messagearea").innerhtml =                 "xypoint(x, y) constructor called";     };     this.debugmessage(); } 

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 -