-->

jquery support works in html but not in .js?

2019-02-20 08:22发布

问题:

Trying out komodo to build a jquery ui widget.. I enabled the jquery api reference and in a .html file it works great.. I then open my widget.js file and type in;

(function($) {

followed by

$.

I would expect to get intellisense here, but instead I get:

No completions found. (Error determining completions)

Is this a file extension thing? Are jquery ui widgets just unsupported?

回答1:

From the guys at Komodo;

The problem is that Komodo doesn't know the context of the anonymous function call - in other words Komodo is not smart enough to know that "jQuery" == "$" in this case.

But all is not lost, you can help out Komodo by telling it what the type is in such cases. Here is the example that uses jsDoc to help define the type of "$":

   (/** @param {jQuery} $ */function($) {
       $. // will show jQuery completions now
   })(jQuery)

;



回答2:

The argument is the problem. Without it:

(function()
  {
  $. //works
  jQuery. //works
  ...
  }
);

Komodo knows both $ and jQuery as globals. Local scope takes precedence, so $ becomes undefined. Conversely, if you pass in jQuery instead, $ will work, but jQuery will not:

(function(jQuery)
  {
  $. //works
  jQuery. //does not
  ...
  }
);