451,12 → 451,12 |
Variables declared inside a function are not accessible from |
outside the function. This can be useful, for example, to hide |
implementation details or to avoid polluting the global scope. |
</P> |
<MOREINFO> |
<URL>http://yura.thinkweb2.com/named-function-expressions/</URL> |
<URL>notes/closures/</URL> |
<URL>http://dmitrysoshnikov.com/ecmascript/chapter-5-functions/#question-about-surrounding-parentheses</URL> |
</MOREINFO> |
</P> |
</CONTENT> |
<CONTENT TITLE="What is a function statement?" ID="functionStatement"> |
<P> |
479,7 → 479,6 |
} catch(e) { _DumpException(e) } |
</CODE> |
</P> |
|
<P> |
Code that uses <DFN>function statement</DFN> has three known interpretations. Some |
implementations process <ICODE>Fze</ICODE> as a <DFN>Statement</DFN>, in order. Others, including |
505,10 → 504,7 |
// Program code |
function aa(b,a){return b.unselectable=a} |
</CODE> |
|
</P> |
|
<P> |
<!-- |
Notable examples of the misuse of the term "function statement" |
can be seen in David Flanagan's "JavaScript: The Definitive Guide", |
522,9 → 518,9 |
<URL>http://groups.google.com/group/comp.lang.javascript/msg/3987eac87ad27966</URL> |
<URL>http://nanto.asablo.jp/blog/2005/12/10/172622</URL> (Article in Japanese) |
</MOREINFO> |
</P> |
</CONTENT> |
</CONTENT> |
|
<CONTENT TITLE="Dates" ID="dates"> |
<P> |
ISO 8601 defines date and time formats. Some benefits include: |
539,7 → 535,6 |
The ISO Extended format for common date is <ICODE>YYYY-MM-DD</ICODE>, and for time is |
<ICODE>hh:mm:ss</ICODE>. |
</P> |
|
<P> |
For an event with an offset from UTC, use <ICODE>YYYY-MM-DDThh:mm:ss±hh:mm</ICODE>. |
</P> |
554,6 → 549,7 |
</P> |
<P> |
Year <ICODE>0000</ICODE> is unrecognized by some formats (XML Schema, <ICODE>xs:date</ICODE>). |
</P> |
<MOREINFO> |
<URL LINKTEXT="ECMA-262 Date.prototype, s. 15.9">#onlineResources</URL> |
<URL LINKTEXT="A summary of the international standard date and time notation, by Markus Kuhn" |
561,14 → 557,12 |
<URL>http://en.wikipedia.org/wiki/ISO_8601</URL> |
<URL LINKTEXT="ISO 8601:2004(E)">res/ISO_8601-2004_E.pdf</URL> |
<URL LINKTEXT="W3C QA Tip: Use international date format (ISO)">http://www.w3.org/QA/Tips/iso-date</URL> |
<URL LINKTEXT="RFC 3339, Date and Time on the Internet: Timestamps |
">http://www.ietf.org/rfc/rfc3339.txt</URL> |
<URL LINKTEXT="RFC 3339, Date and Time on the Internet: Timestamps" |
>http://www.ietf.org/rfc/rfc3339.txt</URL> |
<URL>http://www.w3.org/TR/xmlschema-2/#dateTime</URL> |
</MOREINFO> |
</P> |
|
<CONTENT TITLE="How do I format a Date object with javascript?" |
ID="formatDate" NUMID="4_30"> |
<CONTENT TITLE="How do I format a Date object with javascript?" ID="formatDate" NUMID="4_30"> |
<P> |
A local <ICODE>Date</ICODE> object where <ICODE>0 <= year <= 9999</ICODE> can be |
formatted to a common ISO 8601 format <ICODE>YYYY-MM-DD</ICODE> with:- |
598,7 → 592,7 |
<CONTENT TITLE="How can I create a Date object from a String?" ID="parseDate"> |
<P> |
An Extended ISO 8601 local Date format <ICODE>YYYY-MM-DD</ICODE> can be parsed to a |
Date with the following:- |
Date with the following: |
<CODE> |
/**Parses string formatted as YYYY-MM-DD to a Date object. |
* If the supplied string does not match the format, an |
626,8 → 620,7 |
</CONTENT> |
|
<CONTENT TITLE="Numbers" ID="numbers"> |
<CONTENT TITLE="How do I format a Number as a String with exactly 2 decimal places?" |
ID="formatNumber" NUMID="4_6"> |
<CONTENT TITLE="How do I format a Number as a String with exactly 2 decimal places?" ID="formatNumber" NUMID="4_6"> |
<P> |
When formatting money for example, to format 6.57634 to 6.58, 6.7 to |
6.50, and 6 to 6.00? |
699,14 → 692,13 |
"numberToFixed(0.0000000006, 0) => " + numberToFixed(0.0000000006, 0) |
].join("\n")); |
</CODE> |
</P> |
<MOREINFO> |
<URL>http://www.merlyn.demon.co.uk/js-round.htm</URL> |
<URL>http://msdn.microsoft.com/en-us/library/sstyff0z%28VS.85%29.aspx</URL> |
</MOREINFO> |
</P> |
</CONTENT> |
<CONTENT TITLE="Why does simple decimal arithmetic give strange results?" |
ID="binaryNumbers" NUMID="4_7"> |
<CONTENT TITLE="Why does simple decimal arithmetic give strange results?" ID="binaryNumbers" NUMID="4_7"> |
<P> |
For example, <ICODE>5 * 1.015</ICODE> does not give exactly |
<ICODE>5.075</ICODE> and <ICODE>0.06+0.01</ICODE> does |
727,11 → 719,11 |
commonly need rounding; see <URL |
LINKTEXT="How do I format a Number as a String with exactly 2 decimal places?" |
>#formatNumber</URL> |
</P> |
<MOREINFO> |
<URL>http://msdn.microsoft.com/en-us/library/7wkd9z69%28VS.85%29.aspx</URL> |
<URL>http://www.merlyn.demon.co.uk/js-misc0.htm#DW4</URL> |
</MOREINFO> |
</P> |
<P> |
Otherwise, use <ICODE>Math.round</ICODE> on the results of expressions which |
should be of integer value. |
763,7 → 755,6 |
</ICODE> |
[/omit] --> |
</P> |
<P> |
<MOREINFO> |
<URL>http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Functions/parseInt</URL> |
<URL>http://msdn.microsoft.com/en-us/library/x53yedee%28VS.85%29.aspx</URL> |
770,7 → 761,6 |
<URL>http://docs.sun.com/source/816-6408-10/toplev.htm#1064173</URL> |
<URL>notes/type-conversion/#tcPrIntRx</URL> |
</MOREINFO> |
</P> |
</CONTENT> |
<CONTENT TITLE="Why does 1+1 equal 11? or How do I convert a string to a number?" ID="typeConvert"> |
<P> |
785,14 → 775,13 |
<ICODE>parseFloat(varname)</ICODE>. Form control values are strings, as is the result |
from a <ICODE>prompt</ICODE> dialog. Convert these to numbers before performing |
addition: <ICODE>+'1' + 1</ICODE> results <ICODE>2</ICODE>. |
</P> |
<MOREINFO> |
Additional Notes: <URL>notes/type-conversion/</URL> |
<URL LINKTEXT="Additional Notes">notes/type-conversion/</URL> |
<URL>http://msdn.microsoft.com/en-us/library/67defydd%28VS.85%29.aspx</URL> |
</MOREINFO> |
</P> |
</CONTENT> |
<CONTENT TITLE="How do I generate a random integer from 1 to n?" |
ID="randomNumber" NUMID="4_22"> |
<CONTENT TITLE="How do I generate a random integer from 1 to n?" ID="randomNumber" NUMID="4_22"> |
<P> |
<ICODE>Math.random()</ICODE> returns a value <ICODE>R</ICODE> such that <ICODE>0 <= R < 1.0</ICODE>; therefore: |
<CODE> |
803,12 → 792,12 |
</CODE> |
- gives an evenly distributed random integer in the range from |
<ICODE>0</ICODE> to <ICODE>n - 1</ICODE> inclusive; use <ICODE>getRandomNumber(n)+1</ICODE> for <ICODE>1</ICODE> to <ICODE>n</ICODE>. |
</P> |
<MOREINFO> |
<URL>http://msdn.microsoft.com/en-us/library/41336409%28VS.85%29.aspx</URL> |
<URL>http://docs.sun.com/source/816-6408-10/math.htm</URL> |
How to Deal and Shuffle, see in: <URL>http://www.merlyn.demon.co.uk/js-randm.htm</URL> |
</MOREINFO> |
</P> |
</CONTENT> |
</CONTENT> |
|
834,11 → 823,11 |
a = [], |
e = new Error("My Message."); |
</CODE> |
</P> |
See also: |
<MOREINFO> |
<URL>http://dmitrysoshnikov.com/ecmascript/chapter-7-2-oop-ecmascript-implementation/</URL> |
</MOREINFO> |
</P> |
</CONTENT> |
<CONTENT TITLE="What is a built-in object?" ID="builtInObject"> |
<P> |