Yahoo!WidgetEngineReference-[JavaScript]

JavaScript

Because the XML engine looks for the <> symbols to mark blocks of XML data,
our JavaScript engine needs to have these symbols replaced with < and >
respectively. For example:
XMLエンジンは、データをマーキングするのに<と>の文字を探すようになっているので、ウィジェットのJavaScriptエンジンを使う場合にはこれらの文字を対応するエンティティで置き換えなければならない。たとえば…

<onMouseUp>
if (x &lt; 5)
displayResults();
</onMouseUp>

Alternatively you can use XML comments to hide the JavaScript code from the XML
engine just as is commonly done in HTML, like so:
これに替わる方法として、JavaScriptコードをXMLエンジンから隠すためにXMLコメントを使うこともできる。これは、HTMLで一般的に行われている手法だ。こんな風になる。

<onMouseUp>
<!--
if (x < 5)
displayResults();
//-->
</onMouseUp>

This is generally preferred because it makes the code easier to read.
In version 2.1 or later, you can use CDATA sections (which are actually more correct to
use these days, and largely necessary if you put the parser into strict mode):
この手法を使うとコードが読みやすくなるので、一般的には好まれている。ウィジェットエンジンのバージョン2.1以降では、CDATAセクションを使うこともできる。(最近では、この手法がより正しいと考えられている。いずれにせよ、もしパーザーをStrictモードで動作させている場合にはこの手法が必須となる)

<onMouseUp>
<![CDATA[
if (x < 5)
displayResults();
]]>
</onMouseUp>

You can also make references to external JavaScript which we will cover later.
外部のJavaScriptコードへのリンクを使うこともできるが、これは後ほど説明する。

コメント