I am trying to create a small javascript plugin like this:
function TextShadow(host){
this.host_id=host;
this.welcome=function(){alert('welcome to earth')};
$(function(){
this.welcome();
$(this.host_id).html("<p>hello world</p>");
});
}
I then call it from an other script like this:
var test=new TextShadow("#sample");
but i get this.welcome is not a function.However if i change the previous code to the following one everything works fine:
function TextShadow(host){
this.host_id=host;
this.welcome=function(){alert('welcome to earth')};
var gen=this;
$(function(){
gen.welcome();
$(gen.host_id).html("<p>hello world</p>");
});
}
Can someone explain me why the first piece of code doesn't work while the second does?