• Inheritance in jQuery

    If you have a function in some plugin , that you would like to change to your own needs , you may use inheritance in a very simple way .
    You are writting your own function , lets say : foo , and than using prototype method you add the new function instead of the original one.
    For exmple in jquery.validate.js you have extend of the validator with function called showLabel.
    You can create a new .js file , in which you'll enter your own function , for instance :
    MyFile.js :


    function showLabelNewVersion(element, message) {...}



    at the end just add this line to connect the new functionality to the old name of the function :

    $.validator.prototype.showLabel = showLabelNewVersion;

    Now when your plugin will try to use it's showLabel it"ll get the content of the showLabelNewVersion.

    Good luck.

0 comments:

Leave a Reply

Thanks for sharing your feedback! If your feedback doesn't appear right away, please be patient as it may take a few minutes to publish - or longer if the blogger is moderating comments.