How to use zjrJS.Doc. addArrayComprehension()
Declaration
Goal
To add Array Comprehension from EcmaScript 5 to older browsers. (The browser's javascript implementation is tested to see whether addition should be skipped.)
Typical usage
Call this inside the initialisation function for your web application, before using any of the Array Comprehension abilities. Note that our implementations probably run slower than native ones.
The following abilities are added to the Array prototype:
The following ability is added to the Array constructor:
We have created our implementation by combining the explanations in the EcmaScript Language Specification Version 5, with the existing implementations shown at the Mozilla Developer Network, and other internet resources.
Member Type
Method (no return value).
Parameters
None.
Dependencies
None.
Example
zjrJS.Doc.addArrayComprehension()
Goal
To add Array Comprehension from EcmaScript 5 to older browsers. (The browser's javascript implementation is tested to see whether addition should be skipped.)
Typical usage
Call this inside the initialisation function for your web application, before using any of the Array Comprehension abilities. Note that our implementations probably run slower than native ones.
The following abilities are added to the Array prototype:
- forEach()
- every()
- filter()
- indexOf()
- map()
- reduce() (as of version 20120428t0426)
The following ability is added to the Array constructor:
- isArray()
We have created our implementation by combining the explanations in the EcmaScript Language Specification Version 5, with the existing implementations shown at the Mozilla Developer Network, and other internet resources.
Member Type
Method (no return value).
Parameters
None.
Dependencies
None.
Example
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="zjrJS.version.js" id="zjrJS"></script>
<script type="text/javascript">/* <![CDATA[ */
zjrJS.Doc.addArrayComprehension();
[ "apple", "banana", "coconut", "dumpling" ].forEach(
my.list, zjrJS.Doc.eid("placeholder")
);
var my=({});
my.list = function (itemValue, itemIndex, allItems ) { "use strict";
var D = zjrJS.Doc, li = D.cE( "li" );
D.aC( D.cT( itemValue ), li );
D.aC( li, this );
D = null;
};
/* ]]> */</script>
</head>
<body>
<h1>Which of these is not a fruit?</h1>
<ol id=placeholder></ol>
</body>
</html>