JavaScript覆盖方法

时间:2018-12-01 16:44:07

标签: javascript jquery

我想用自己的版本覆盖javascript方法。

让我解释一下,您有以下代码(部分代码)

Reports_Edit_Js("Reports_Edit1_Js",{},{

    relatedModulesMapping  : false,
    step1Container : false,
    secondaryModulesContainer : false,

    init : function() {
        this.initialize();
    },
    /**
     * Function to get the container which holds all the reports step1 elements
     * @return jQuery object
     */
    getContainer : function() {
        return this.step1Container;
    },


    DateToYMD : function (date) {
        var year, month, day;
        year = String(date.getFullYear());
        month = String(date.getMonth() + 1);
        if (month.length == 1) {
            month = "0" + month;
        }
        day = String(date.getDate());
        if (day.length == 1) {
            day = "0" + day;
        }
        return year + "-" + month + "-" + day;
    }
}

现在的问题是,是否可以使用自定义方法覆盖Reports_Edit1_Js中的DateToYMD方法,而无需更改原始文件或定义所有方法。

我尝试了以下代码,但无法正常工作

Reports_Edit_Js("Reports_Edit1_Js").prototype.DateToYMD = function(date){
        var year, month, day;
        year = String(date.getFullYear());
        month = String(date.getMonth() + 1);
        if (month.length == 1) {
            month = "0" + month;
        }
        day = String(date.getDate());
        if (day.length == 1) {
            day = "0" + day;
        }
        return year + "/" + month + "/" + day;
};

Complete code is here也是Reports_Edit_Js

0 个答案:

没有答案