jquery support works in html but not in .js?

不打扰是莪最后的温柔 提交于 2019-12-09 03:24:32

问题


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


来源:https://stackoverflow.com/questions/10933922/jquery-support-works-in-html-but-not-in-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!