How to call a function during object construction in Javascript? -
i want create object , run 2 of methods on object creation. if object
function newobj(){ this.v1 = 10; this.v2 = 20; this.func1 = function(){ ....}; this.func2 = function(){...}; }
and call object
var temp = new newobj();
i want run func1()
, func2()
without calling them explicity on temp variable, temp.func1()
. want them called when create new object variable. tried putting this.func1()
inside newobj
declaration doesn't seem work.
add method invocation statements in constructor:
function newobj(){ this.v1 = 10; this.v2 = 20; this.func1 = function(){ ....}; this.func2 = function(){...}; this.func1(); this.func2(); }
i think solution of needs.
Comments
Post a Comment