if (!wysiwyg_toolbarButtons) {
var wysiwyg_toolbarButtons = new Array(
//command, display name, value, title, prompt/function, default text
["bold", "Strong", WYSIWYG_VALUE_NONE, "Give text strength"],
["italic", "Emphasis", WYSIWYG_VALUE_NONE, "Give text emphasis"],
["createlink", "Link", WYSIWYG_VALUE_PROMPT, "Create a hyperlink", "Enter the URL:", "http://"],
["unlink", "Unlink", WYSIWYG_VALUE_NONE, "Remove hyperlink"],
["insertimage", "Image", WYSIWYG_VALUE_PROMPT, "Insert an image", "Enter the URL of the image:", "http://"],
["inserthorizontalrule", "Rule", WYSIWYG_VALUE_NONE, "Insert horizontal rule"],
["div"], // place a toolbar divider
["formatblock", "Headling 1", "<H1>", "Make top level heading"],
["formatblock", "Headling 2", "<H2>", "Make 2nd level heading"],
["formatblock", "Headling 3", "<H3>", "Make 3rd level heading"],
["formatblock", "Paragraph", "<P>", "Make a paragraph"],
["formatblock", "Monospace", "<PRE>", "Make paragraph monospaced text"],
["insertunorderedlist", "List", null, "Make an unordered list"],
["insertorderedlist", "Ordered List", null, "Make an ordered list"],
["div"], // place a toolbar divider
["toggleview", "Source", "Compose", "Switch views"]
);
}
Run Code Online (Sandbox Code Playgroud)
我的问题是:为什么不报告"ReferenceError:wysiwyg_toolbarButtons未定义"?
Web浏览器中的JavaScript搜索窗口对象中的属性.访问未知属性不会引发错误,因此实际上它被评估为如下所示:
if( !window.wysiwyg_toolbarButtons ) { }
Run Code Online (Sandbox Code Playgroud)
尝试if( !wtf ) { alert('error'); }并if( !window.wtf ) { alert('no error'); }在Firebug控制台中.
编辑
目前,firebug中的控制台使用了代码with( window ) { ..console..code.. }.但是"with"语句很棘手,例如:
>>> alert(location);
= eval( "with( window ) { alert(location); }" );
OK, "location" attribute found in window
>>> alert(wtf);
= eval( "with( window ) { alert(wtf); }" );
ERROR, "wtf" not found in window, and not in global scope, throws ReferenceError
Run Code Online (Sandbox Code Playgroud)
浏览器中的隐式窗口对象的行为与"with"语句使用的行为不同.