jquery support works in html but not in .js?

589 views Asked by At

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?

2

There are 2 answers

0
XeroxDucati On

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
Paul Sweatte On

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
  ...
  }
);