tags:

views:

33

answers:

1
$.fn.myTest=function() {
 var externalfunc=function(){
  alert('haii'); 
 }
};

$.fn.myTest.sample=function(){
 var self = this;
 self.myTest.externalfunc();
}

Can someone tell me how to correct this?

+1  A: 

I have no clue what you are trying to do here. If you extend the jQuery .fn. namespace, all jQuery objects inherit that propertys via prototypal inheritance.

jQuery.fn.myTest = function() {
   var foobar = function(){
       alert('yay');
   };
};

That means $('somelement').myTest() is now available, but you cannot access foobar() here since foobar() is a private member of myTest() (-> function scope). So is your externalfunc().

You could do something like

jQuery.fn.myTest = function() {
   return (function(){
       alert('yay');
   }());
};

That now would really alert on jQuery('element').myTest(), but I doubt that is what you want to achieve. You always should return this within a .fn. method, to preserve the object chain.

jAndy
thanks andy... i will try to changes mycode with another way...
comenk