所以我从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');
如何重写代码以使其更具可读性?感谢。
答案 0 :(得分:1)
代码扩展为以下内容:
function EA() { vart = this; t.error = false; t.inlinePopup = [{ popup_id: "area_search_replace", icon_id: "search" }, { popup_id: "edit_area_help", icon_id: "help" }]; t.plugins = {}; t.line_number = 0; parent.eAL.set_browser_infos(t); if (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 = false; t.highlight_selection_line = null; text = text.replace(sy["custom_regexp"]['after'][i]['regexp'], convert); } } return text; }; var editArea = eA; EditArea = EA;
但它有语法错误,因此根本不起作用。
答案 1 :(得分:0)
我不确定我是否真的理解这个问题,但我敢说你要么拆分字符串了:
editAreaLoader.iframe_script= "<script type='text/javascript'>" +
"Ã EA(){" +
"vart=Á;" +
...
...或从外部文件加载内容:
editAreaLoader.iframe_script= "<script type='text/javascript' src='/path/fo/file.js'>" +