简体   繁体   中英

jQuery plugin call internal function

I want to call removeSomething() (see in line 9) internally:

JS-Code is:

    (function($){
      $.fn.extend({
        Engine: function(options) {
          var defaults = {
           ...
          };
          var options = $.extend(defaults, options);

          removeSomething();

          //-----------------------------------------------------------------------
          //Public Functions ------------------------------------------------------
          //-----------------------------------------------------------------------

          this.removeSomething = function() {
            ...
          }; 
        }
      });
   })(jQuery);

But if I call removeSomething console outputs that removeSomething is not a function, how do I have to call this function? The function should be available internally and externally.

Thanks for help!

When declaring it with var or other = function() {... syntax, the function needs to be defined before you use it, and called however it was defined, in this case:

this.removeSomething = function() {
  ...
}; 
//*then*
this.removeSomething();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM