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
Post a Comment