This means
With Delphi,
Program configuration data is typically read from an ASCII file. ini files are common with Windows application. cfg files are common with other systems. Web applications tend to use JASON and xml files.
Unfortunately, there is no way for a web page to automatically read a simple text file unless a server is used - an understandable security precaution. As a result, many of my applications place the configuration data in a javascript file. As a rule, these files contain only data and no methods (functions).
Arrays
var images_array = [ [ 1, 780,3350, "1","1904 maneuvers No 1"], [ 2, 600,3144, "2","1904 maneuvers No 2"], [ 3, 850,2900, "3","1904 maneuvers No 3"], [15, 476,3336,"15","1904 maneuvers No 15"], [30,3427,5180,"30","1904 maneuvers No 30"], [31,3613,6212,"31","1904 maneuvers No 31"], [52,4216,3332,"52","1904 maneuvers No 52"] ] |
Objects
someObject = { param1 : 4, param2 : "any string", paramn : "another string" // no comma after the last parameter } |
x = someObject.param1; // uses dot notation someObject.param1 = 12; // more dot notation s = someObject["param2"]; // uses array syntax |
Objects of Objects
|
Property | |
---|---|
label | Label for the data input field |
value | The default value for the data input field |
explanation | This is displayed when the mouse moves over the label |
The associated display components are not coded in the html file. Instead, they are created (via javascript) inside a couple of div elements similar to the following.
| |
_ref = Application.inputBoxes; for (inputName in _ref) { inputObject = _ref[inputName]; inputElement = document.getElementById(inputName + "-input"); inputElement.innerHTML = '<input name="' + inputName + '" value="' + inputObject.value + '">'; inputElement = document.getElementById(inputName + "-expl"); inputElement.innerHTML = inputObject.label; } |
inputElement.addEventListener('change', (function(evt) { var _ref1, inputName; inputName = evt.target.name; if ((_ref1 = Application.inputBoxes[inputName]) != null) { _ref1.value = evt.target.value; } }), false); |
More Examples
|
|
Tabular data
var someArray = new Array( 100 ); // this defines the size var someArray_count = 0; function mcAddToSomeArray(year, co2Concentration){ var temp = new Object(); temp.year = year; temp.Concentration = co2Concentration; someArray[someArray_count] = temp; someArray_count++; } mcAddToSomeArray(1958, 316.16); mcAddToSomeArray(1959, 316.04); mcAddToSomeArray(1960, 317.17); mcAddToSomeArray(1961, 318.04); // many more entries below this |
for (var i = 0; i < someArray_count; i++) { var CO2 = someArray[i].Concentration ; var year = someArray[i].year; var temp = Sensitivity * mcLog2(CO2/baseCO2) + baseTemp ; x.push( year ); // These arrays are used y.push( temp ); // to plot the data } |
This is an alternate technique using a variable size array and push.
var someArray = []; function mcAddToSomeArray(year, co2Concentration){ var temp = new Object(); temp.year = year; temp.Concentration = co2Concentration; someArray.push(temp); } |
Array | mcArray = [];
square brackets
| Object
| mcObject = {};
| curly braces
| |
integer | someArray[0][0]
Value
| year = 0
| someArray[0][year]
| Variable
| |
dot notation | someArray[0].year
No quotes
| string
| someArray[0]["year"]
| Either double or single quotes required
| yr = 'year'
| someArray[0][yr]
| String variable
| |
Javascript has 2 different types of objects, the newer versions include a third type using the class keyword.
Object literal | someObject = {};
In the examples above, good when only one instance is required
| Class definition | Object prototype function TsomeObject(){} | someObject = new TsomeObject() Used when several instances are required
| The function is just the class constructor, methods are defined via the prototype property I always start class definitions with a capital-T (for type) class keyword
| class TsomeClass{} | someObject = new TsomeClass() This is a far superior interface, | but is NOT supported in many browsers |
The techniques described above are almost identical to the JSON (JavaScript Object Notation) data-interchange format with the following exceptions.
yy = JSON.stringify(xx); // xx is either an object or an array zz = JSON.parse(yy); // yy is a JSON string |