jQuery.extend和jQuery.fn.extend之间的区别? [英] Difference between jQuery.extend and jQuery.fn.extend?

查看:216
本文介绍了jQuery.extend和jQuery.fn.extend之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图了解jquery插件的语法,因为我想将两个插件合并到 一.还需要能够间歇性停止或运行多次的信号灯.

I am trying to understand the jquery plugin syntax, because I want to merge two plugins into one. The blinker that also needs to be able to stop de interval or run a number of times.

无论如何, 这个语法和

Anyway, is this syntax the same as

jQuery.fn.extend({
    everyTime: function(interval, label, fn, times) {
        return this.each(function() {
            jQuery.timer.add(this, interval, label, fn, times);
        });
    },
    oneTime: function(interval, label, fn) {
        return this.each(function() {
            jQuery.timer.add(this, interval, label, fn, 1);
        });
    },

$.fn.blink = function(options)
    {

因为看起来first(without =)是一次设置多个方法的方法. 这是正确的吗? 还在我在这里的时候 将元素和一些逻辑添加到jquery对象的原因是什么?

because it looks like the first(without =) is a way to set multiple methods at once. Is this right? Also while I am here What would be the reason to add the elements and some logic to the jquery object?

jQuery.extend({
    timer: {
        global: [],
        guid: 1,
        dataKey: "jQuery.timer",

(来自计时器插件)

推荐答案

jQuery.extend用于扩展具有附加功能的任何对象,但是jQuery.fn.extend用于扩展jQuery.fn对象,实际上它添加了一口气几个插件功能(而不是分别分配每个功能).

jQuery.extend is used to extend any object with additional functions, but jQuery.fn.extend is used to extend the jQuery.fn object, which in fact adds several plugin functions in one go (instead of assigning each function separately).

jQuery.extend :

var obj = { x: function() {} }

jQuery.extend(obj, { y: function() {} });

// now obj is an object with functions x and y

jQuery.fn.extend :

jQuery.fn.extend( {
        x: function() {},
        y: function() {}
});

// creates 2 plugin functions (x and y)

这篇关于jQuery.extend和jQuery.fn.extend之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆