0

所以我从 EDITAREA 一个网络荧光笔中得到了这个代码片段,我怎样才能重写它以使其更具可读性而不破坏代码输出行为?

editAreaLoader.iframe_script= "<script type='text/javascript'> Ã EA(){vart=Á;t.error=Ì;t.inlinePopup=[{popup_id:\"area_search_replace\",icon_id:\"search\"},{popup_id:\"edit_area_help\",icon_id:\"help\"}];t.plugins={};t.line_number=0;È.eAL.set_browser_infos(t);if(t.isIE >=8)t.isIE=7;t.É={};t.last_text_to_highlight=\"\";t.last_hightlighted_text=\"\";t.syntax_list=[];t.allready_used_syntax={};t.check_line_selection_timer=50;t.ÂFocused=Ì;t.highlight_selection_line=null; text=text.replace(sy[\"custom_regexp\"]['after'][i]['regexp'],convert);}}return text;};var editArea= eA;EditArea=EA;</script>".replace(/Á/g,'this').replace(/Â/g,'textarea').replace(/Ã/g,'function').replace(/Ä/g,'prototype').replace(/Å/g,'settings').replace(/Æ/g,'length').replace(/Ç/g,'style').replace(/È/g,'parent').replace(/É/g,'last_selection').replace(/Ê/g,'value').replace(/Ë/g,'true').replace(/Ì/g,'false');

如何重写代码以使其更具可读性?谢谢。

4

2 回答 2

1

代码扩展如下:

函数 EA() {
    变体=这个;
    t.error = 假;
    t.inlinePopup = [{
        popup_id: "area_search_replace",
        icon_id: "搜索"
    }, {
        popup_id: "edit_area_help",
        icon_id:“帮助”
    }];
    t.plugins = {};
    t.line_number = 0;
    parent.eAL.set_browser_infos(t);
    如果 (t.isIE >= 8) t.isIE = 7;
    t.last_selection = {};
    t.last_text_to_highlight = "";
    t.last_hightlighted_text = "";
    t.syntax_list = [];
    t.allready_used_syntax = {};
    t.check_line_selection_timer = 50;
    t.textareaFocused = 假;
    t.highlight_selection_line = null;
    text = text.replace(sy["custom_regexp"]['after'][i]['regexp'], convert);
}
}
返回文本;
};
var 编辑区域 = eA;
编辑区 = EA;

但它有语法错误,因此根本不起作用。

于 2013-02-11T10:00:06.067 回答
0

我不确定我是否真的理解这个问题,但我敢说你要么想要拆分字符串:

editAreaLoader.iframe_script= "<script type='text/javascript'>" +
    "Ã EA(){" +
    "vart=Á;" +
    ...

...或从外部文件加载内容:

 editAreaLoader.iframe_script= "<script type='text/javascript' src='/path/fo/file.js'>" +
于 2013-02-11T09:58:04.117 回答