简体   繁体   English

TypeScript中的JQuery和JQueryStatic接口有什么区别?

[英]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.

相关问题 在Typescript中,类型和接口有什么区别? - In Typescript, what is the difference between type and interface? 在 Typescript 中使用 `: Interface` 和 `as Interface` 有什么区别? - What's the difference between using `: Interface` and `as Interface` in Typescript? TypeScript中“声明类”和“接口”有什么区别 - What's the difference between "declare class" and "interface" in TypeScript TypeScript声明合并中的导出接口和导出默认接口之间有什么区别? - What's the difference between export interface and export default interface in typescript declaration merging? 我是否需要使用TypeScript在JQueryStatic定义文件中声明所有JQuery原型? - Do I need to declare all my JQuery prototypes in a JQueryStatic definition file with TypeScript? web api 和接口有什么区别? - What is the difference between web api and interface? 打字稿中的String []和[String]有什么区别? - What's the difference between String[] and [String] in typescript ? TypeScript / JavaScript中的模块和命名空间有什么区别? - What is the difference between Modules and Namespaces in TypeScript/JavaScript? 在Typescript中这两个数组赋值有什么区别? - What is the difference between these two array assignments in Typescript? 打字稿中的枚举和对象有什么区别 - What is the difference between enum and object in typescript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM