1

I am trying to inherit a method from base widget to another widget. here is my sample code

My base widget is

$(function () {
    $.widget("UI.baseWidget", {
        options: {
            testVal:''
        },
        _create: function () {
            alert(this.option.testVal);
        },

    });
});

and other widget calling this base widget is

$(function () {
    $.widget("UI.MyWidget", $.UI.baseWidget, {
        options: {
          testVal:''
        },
        _create: function () {
            $.UI.baseWidget.prototype._create.call(this);
        }

    });
});

and initilise the MyWidgetcode is'

$('#mydiv').MyWidget({testVal:'test widget'})

How can we pass testVal option from MyWidget to baseWidget call? and I getting error some thing like

Uncaught TypeError: i is not a constructor

Uncaught TypeError: $(...).MyWidget is not a function

can please help me to fix this issue. thanks in advance

1 Answer 1

2

Seems to work OK: I only made one correction : changed option to options in alert(this.option.testVal); and the alert with 'test widget' popped up OK. You can also try to create the widget jquery onReady and see if that fixes the problem i.e. :

$(function () {
    $('#myDiv').MyWidget({testVal:'test widget'});
});

See my code at https://jsfiddle.net/5gmn6x7k/4/

Sign up to request clarification or add additional context in comments.

2 Comments

HI @Dhananjay I already include the Jqury UI Library . Still the error is there " Uncaught TypeError: i is not a constructor"
@Arun Create a new fiddle or modify my fiddle code to replicate the problem if possible

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.