How to Extend Twitter Bootstrap Plugin

后端 未结 5 1907
面向向阳花
面向向阳花 2020-11-27 02:43

I am digging into Twitter\'s Bootstrap and now want to try and add some functionality to the plugins, but I can\'t figure out how to do so. Using the modal plugin as an exa

5条回答
  •  自闭症患者
    2020-11-27 03:20

    For the record there is a simple method to override or extend existing functions:

    var _show = $.fn.modal.Constructor.prototype.show;
    
    $.fn.modal.Constructor.prototype.show = function() {
        _show.apply(this, arguments);
        //Do custom stuff here
    };
    

    Doesn't cover custom arguments, but it's easy as well with the method above; instead of using apply and arguments, specify the original arguments plus the custom ones in the function definition, then call the original _show (or whichever it is) with the original arguments, and finally do other stuff with the new arguments.

提交回复
热议问题