尝试扩展小部件时出错,为什么?

时间:2015-01-15 15:57:25

标签: jquery widget

这是两个小部件。

http://pastebin.com/kheULT7h

如果我尝试从'sb.baseApp'扩展'sb.textboxesApp',我会收到错误:

“TypeError:s不是构造函数”

但为什么???

这不是你如何扩展小部件吗?

jquery 1.8.3 jquery ui 1.10.3

1 个答案:

答案 0 :(得分:0)

我认为您应该将小部件本身作为.widget()的第二个参数传递。不是字符串。这是我的测试。 http://jsfiddle.net/ho873kz4/

/****************************

Base Widget

        Requires jQuery
        Requires jQuery UI

****************************/

(function($, undefined) {
        'use_strict';



        /*
        * A widget.
        */
        $.widget('sb.baseApp', {
                /*
                * Widget Option
                */
                options: {},



                /*
                * Constructor, called once when first created
                */
                _create: function() {
                    console.log('baseApp created');
                },

                /*
                * Initialisation, called after _create and and on later widget calls.
                */
                _init: function() {
                },

                /*
                * Destructor, cleanup when no longer needed.
                */
                _destroy: function() {
                }
        });
} (jQuery));



/****************************

Textbox Widget

        Requires jQuery
        Requires jQuery UI

****************************/

(function($, undefined) {
        'use_strict';



        /*
        * A widget
        */
        $.widget('sb.textboxesApp', $.sb.baseApp, {
                /*
                * Widget Option
                */
                options: {},



                /*
                * Constructor, called once when first created
                */
                _create: function() {
                    console.log('textboxesApp create');
                    return this._super();
                },

                /*
                * Initialisation, called after _create and and on later widget calls.
                */
                _init: function() {
                },

                /*
                * Destructor, cleanup when no longer needed.
                */
                _destroy: function() {
                }
        });
} (jQuery));

jQuery.sb.textboxesApp();