js中怎么覆盖其他js的方法

解决方案 »

  1.   

    第三方实例.prototype.fn = '重写的函数'
      

  2.   

    <script type="text/javascript">
    // <![CDATA[
    // <![CDATA[
    //
    // LIBRARY REQUIREMENTS
    //
    // In the require function, we include the necessary libraries and modules for
    // the HTML dashboard. Then, we pass variable names for these libraries and
    // modules as function parameters, in order.
    //
    // When you add libraries or modules, remember to retain this mapping order
    // between the library or module and its function parameter. You can do this by
    // adding to the end of these lists, as shown in the commented examples below.require([
        "splunkjs/mvc",
        "splunkjs/mvc/utils",
        "splunkjs/mvc/tokenutils",
        "underscore",
        "jquery",
        "splunkjs/mvc/simplexml",
        "splunkjs/mvc/layoutview",
        "splunkjs/mvc/simplexml/dashboardview",
        "splunkjs/mvc/simplexml/dashboard/panelref",
        "splunkjs/mvc/simplexml/element/chart",
        "splunkjs/mvc/simplexml/element/event",
        "splunkjs/mvc/simplexml/element/html",
        "splunkjs/mvc/simplexml/element/list",
        "splunkjs/mvc/simplexml/element/map",
        "splunkjs/mvc/simplexml/element/single",
        "splunkjs/mvc/simplexml/element/table",
        "splunkjs/mvc/simplexml/element/visualization",
        "splunkjs/mvc/simpleform/formutils",
        "splunkjs/mvc/simplexml/eventhandler",
        "splunkjs/mvc/simplexml/searcheventhandler",
        "splunkjs/mvc/simpleform/input/dropdown",
        "splunkjs/mvc/simpleform/input/radiogroup",
        "splunkjs/mvc/simpleform/input/linklist",
        "splunkjs/mvc/simpleform/input/multiselect",
        "splunkjs/mvc/simpleform/input/checkboxgroup",
        "splunkjs/mvc/simpleform/input/text",
        "splunkjs/mvc/simpleform/input/timerange",
        "splunkjs/mvc/simpleform/input/submit",
        "splunkjs/mvc/searchmanager",
        "splunkjs/mvc/savedsearchmanager",
        "splunkjs/mvc/postprocessmanager",
        "splunkjs/mvc/simplexml/urltokenmodel"
        // Add comma-separated libraries and modules manually here, for example:
        // ..."splunkjs/mvc/simplexml/urltokenmodel",
        // "splunkjs/mvc/tokenforwarder"
        ],
        function(
            mvc,
            utils,
            TokenUtils,
            _,
            $,
            DashboardController,
            LayoutView,
            Dashboard,
            PanelRef,
            ChartElement,
            EventElement,
            HtmlElement,
            ListElement,
            MapElement,
            SingleElement,
            TableElement,
            VisualizationElement,
            FormUtils,
            EventHandler,
            SearchEventHandler,
            DropdownInput,
            RadioGroupInput,
            LinkListInput,
            MultiSelectInput,
            CheckboxGroupInput,
            TextInput,
            TimeRangeInput,
            SubmitButton,
            SearchManager,
            SavedSearchManager,
            PostProcessManager,
            UrlTokenModel        // Add comma-separated parameter names here, for example:
            // ...UrlTokenModel,
            // TokenForwarder
            ) {        var pageLoading = true;
            //
            // TOKENS
            //        // Create token namespaces
            var urlTokenModel = new UrlTokenModel();
            mvc.Components.registerInstance('url', urlTokenModel);
            var defaultTokenModel = mvc.Components.getInstance('default', {create: true});
            var submittedTokenModel = mvc.Components.getInstance('submitted', {create: true});        urlTokenModel.on('url:navigate', function() {
                defaultTokenModel.set(urlTokenModel.toJSON());
                if (!_.isEmpty(urlTokenModel.toJSON()) && !_.all(urlTokenModel.toJSON(), _.isUndefined)) {
                    submitTokens();
                } else {
                    submittedTokenModel.clear();
                }
            });        // Initialize tokens
            defaultTokenModel.set(urlTokenModel.toJSON());        function submitTokens() {
                // Copy the contents of the defaultTokenModel to the submittedTokenModel and urlTokenModel
                FormUtils.submitForm({ replaceState: pageLoading });
            }        function setToken(name, value) {
                defaultTokenModel.set(name, value);
                submittedTokenModel.set(name, value);
            }        function unsetToken(name) {
                defaultTokenModel.unset(name);
                submittedTokenModel.unset(name);
            }        //
            // SEARCH MANAGERS
            //        
    var search1 = new SearchManager({
                "id": "search1",
                "status_buckets": 0,
                "sample_ratio": null,
                "earliest_time": "0",
                "cancelOnUnload": true,
                "search": "|makeresults|eval  ip=\"$ips$\", address=\"$address$\",mask=\"$mask$\",mask_num=\"$masknum$\" | table ip address mask mask_num",
                "latest_time": "$latest$",
                "app": utils.getCurrentApp(),
                "auto_cancel": 90,
                "preview": true,
                "tokenDependencies": {
                },
                "runWhenTimeIsUndefined": false
            }, {tokens: true, tokenNamespace: "submitted"});
            //
            // SPLUNK LAYOUT
            //        $('header').remove();
            new LayoutView({"hideChrome": false, "hideAppBar": false, "hideSplunkBar": false})
                .render()
                .getContainerElement()
                .appendChild($('.dashboard-body')[0]);        //
            // DASHBOARD EDITOR
            //        new Dashboard({
                id: 'dashboard',
                el: $('.dashboard-body'),
                showTitle: true,
                editable: true
            }, {tokens: true}).render();
            //
            // VIEWS: VISUALIZATION ELEMENTS
            //        var element1 = new TableElement({
                "id": "element1",
                "count": 10,
                "dataOverlayMode": "none",
                "drilldown": "cell",
                "refresh.display": "progressbar",
                "rowNumbers": "true",
                "wrap": "true",
                "managerid": "search1",
                "el": $('#element1')
            }, {tokens: true, tokenNamespace: "submitted"}).render();
            //
            // VIEWS: FORM INPUTS
            //        var input1 = new TextInput({
                "id": "input1",
                "default": "",
                "value": "$form.ips$",
                "el": $('#input1')
            }, {tokens: true}).render();        input1.on("change", function(newValue) {
                FormUtils.handleValueChange(input1);
            });
            
            var input2 = new TextInput({
                "id": "input2",
                "value": "$form.address$",
                "el": $('#input2')
            }, {tokens: true}).render();        input2.on("change", function(newValue) {
                FormUtils.handleValueChange(input2);
            });
            
            var input3 = new DropdownInput({
                "id": "input3",
                "choices": [
                    {"label": "\u7537", "value": "\u7537"},
                    {"label": "\u5973", "value": "\u5973"}
                ],
                "showClearButton": true,
                "selectFirstChoice": false,
                "value": "$form.mask$",
                "el": $('#input3')
            }, {tokens: true}).render();        input3.on("change", function(newValue) {
                FormUtils.handleValueChange(input3);
            });
            
            var input4 = new TextInput({
                "id": "input4",
                "value": "$form.masknum$",
                "el": $('#input4')
            }, {tokens: true}).render();        input4.on("change", function(newValue) {
                FormUtils.handleValueChange(input4);
            });
                    //
            // SUBMIT FORM DATA
            //        var submit = new SubmitButton({
                id: 'submit',
                el: $('#search_btn')
            }, {tokens: true}).render();        submit.on("submit", function() {
                submitTokens();
            });        // Initialize time tokens to default
            if (!defaultTokenModel.has('earliest') && !defaultTokenModel.has('latest')) {
                defaultTokenModel.set({ earliest: '0', latest: '' });
            }        if (!_.isEmpty(urlTokenModel.toJSON())){
                submitTokens();
            }
            //
            // DASHBOARD READY
            //        DashboardController.ready();
            pageLoading = false;    }
    );
    // ]]>
    </script>
    这个里面的内容不能修改,怎么才能把它替换掉,或者清除掉,换用自己的
      

  3.   

    不同的framework可能会有不同的override方式。
    你最好查看相应的api。