[英]What is the difference between the JQuery and the JQueryStatic interface in TypeScript?
Can someone explain this? 有人可以解释吗? I realize the jQuery interface is the one that comes pre defined but what is JQueryStatic?
我意识到jQuery接口是预定义的接口,但是JQueryStatic是什么?
I have the following: 我有以下内容:
(function($)
{
$.fn.disableBt = function()
{
$(this).attr('disabled', true);
if ($.browser.msie && $.browser.version < 9)
{
$(this).addClass('disabled');
}
}
})(jQuery);
The only way I could get typescript to know about this was by adding it to the jQuery interface like this: 我能使打字稿了解这一点的唯一方法是将其添加到jQuery接口中,如下所示:
disableBt();
}
I tried adding it to jQueryStatic but it didn't seem to work: 我尝试将其添加到jQueryStatic中,但似乎不起作用:
interface JQueryStatic {
modal( options );
disableBt();
}
Here's the way options is defined in my modal: 这是在我的模态中定义选项的方式:
$.modal.defaults = {
content: false,
useIframe: false,
...
...
var settings = $.extend({}, $.modal.defaults, options),
Is "options" (in modal (options)) defined? 是否定义了“选项”(以模式(选项))?
JQueryStatic interface has the static methods ("those on $ and jQuery themselves") JQueryStatic接口具有静态方法(“ $和jQuery本身的方法”)
JQuery interface has the members that can be run on jQuery elements, many of them are returning JQuery themselves for chainability. JQuery接口具有可在jQuery元素上运行的成员,其中许多成员都返回JQuery自身以实现可链接性。
interface JQueryStatic {
someAdditionalMethod(): any;
}
$.someAdditionalMethod();
interface JQuery {
pluginMethod(): JQuery;
}
$("body").pluginMethod();
if your case something like this: 如果您的情况是这样的:
interface ModalDefaultOptions {
content?: bool;
useIframe?: bool;
}
interface JQueryStatic {
modal: {
defaults: ModalDefaultOptions;
};
}
interface JQuery {
disableBt(): void; // or :JQuery if you returned 'this' from the function
}
$("#someButton").disableBt();
$.modal.defaults.content = false;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.