Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Feb 24, 2013 05:35 AM by raju dasa
Contributor
3388 Points
873 Posts
Feb 22, 2013 10:11 PM|LINK
Hard to find the right subject for this, but I will give an example.
MyClass=function(){
this.process=function(p){....}
}
I can use it like this
var myInstance=MyClass();
anythingneedafunction=function(item){ myInstance.process(item);}
but I think it is nice to put that assign into the class, so something like this
anythingneedafunction=function(item){ this.process(item);}
but that doesn't work, I guess it is something about Class/Instance.
Is there a way to do thing like that?
Thanks
Star
14378 Points
2445 Posts
Feb 24, 2013 05:35 AM|LINK
Hi,
Try this code:
var MyClass=function(){ this.process=function(p){ console.log(p); }; this.anythingneedafunction=function(item){ this.process(item);}; }; var myInstance=new MyClass(); myInstance.anythingneedafunction("one");
wyx2000
Contributor
3388 Points
873 Posts
Any way to assign instance function in a class?
Feb 22, 2013 10:11 PM|LINK
Hard to find the right subject for this, but I will give an example.
MyClass=function(){
this.process=function(p){....}
}
I can use it like this
var myInstance=MyClass();
anythingneedafunction=function(item){ myInstance.process(item);}
but I think it is nice to put that assign into the class, so something like this
MyClass=function(){
anythingneedafunction=function(item){ this.process(item);}
this.process=function(p){....}
}
var myInstance=MyClass();
but that doesn't work, I guess it is something about Class/Instance.
Is there a way to do thing like that?
Thanks
raju dasa
Star
14378 Points
2445 Posts
Re: Any way to assign instance function in a class?
Feb 24, 2013 05:35 AM|LINK
Hi,
Try this code:
var MyClass=function(){ this.process=function(p){ console.log(p); }; this.anythingneedafunction=function(item){ this.process(item);}; }; var myInstance=new MyClass(); myInstance.anythingneedafunction("one");rajudasa.blogspot.com || blog@opera