uxsolutions / bootstrap-datepicker

A datepicker for twitter bootstrap (@twbs)
Apache License 2.0
12.66k stars 6.06k forks source link

noConflict causes issue with deprecated methods #2705

Open inneslu opened 2 months ago

inneslu commented 2 months ago

Expected behaviour

Deprecated function should run it's alias, and not error. Deprecated message should appear in console.

Actual behaviour

Error is thrown; $.fn.datepicker.deprecated not a function

Datepicker version used

1.8 - however, issue is still present in latest version - if any methods use the deprecated message.

Example code

var datepicker = $.fn.datepicker.noConflict();
$.fn.bootstrapDP = datepicker;

$('.datepicker').bootstrapDP({options});
$('.datepicker').bootstrapDP('remove');

Reason why issue is occuring

Deprecated function is being assigned to datepicker:

$.fn.datepicker.deprecated = function(msg){
        var console = window.console;
        if (console && console.warn) {
            console.warn('DEPRECATED: ' + msg);
        }
    };

No conflict is reverting the datepicker function:

$.fn.datepicker.noConflict = function(){
        $.fn.datepicker = old;
        return this;
    };

Alias function is referring to datepicker - which has since been reverted (i.e. no deprecated function exists):

function alias(method, deprecationMsg){
        return function(){
            if (deprecationMsg !== undefined) {
                $.fn.datepicker.deprecated(deprecationMsg);
            }

            return this[method].apply(this, arguments);
        };
    }