20,741
edits
Line 79: | Line 79: | ||
append(PFDVector, PrimaryFlightDisplay.new() ); | append(PFDVector, PrimaryFlightDisplay.new() ); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== Initialization / Constructor == | |||
Once these changes are in place, you can easily initialize your members/fields using a single foreach() loop, i.e. instead of having something like this: | |||
<syntaxhighlight lang="nasal"> | |||
curAlt1 = pfd.getElementById("curAlt1"); | |||
curAlt2 = pfd.getElementById("curAlt2"); | |||
curAlt3 = pfd.getElementById("curAlt3"); | |||
vsPointer = pfd.getElementById("vsPointer"); | |||
curAltBox = pfd.getElementById("curAltBox"); | |||
curSpd = pfd.getElementById("curSpd"); | |||
curSpdTen = pfd.getElementById("curSpdTen"); | |||
spdTrend = pfd.getElementById("spdTrend"); | |||
</syntaxhighlight> | |||
You could use this | |||
<syntaxhighlight lang="nasal"> | |||
var PrimaryFlightDisplay { | |||
new: func() { | |||
var m = {parents:[PrimaryFlightDisplay]}; | |||
m.symbols = {}; | |||
foreach(var symbol; ['curAlt1','curAlt2','curAlt3','vsPointer','curAltBox','curSpd','curSpdTen','curAlt1','spdTrend',]) | |||
me.symbols[symbol] = me.getElementById(symbol); | |||
}, # new() | |||
} # PrimaryFlightDisplay | |||
</syntaxhighlight> | |||
All the original foo=nil initialization can now be removed, this is 100% equivalent, and saves you tons of typing and time! | |||
== Dealing with Properties == | == Dealing with Properties == | ||
Line 101: | Line 129: | ||
This would then be the place for your instance-specific properties. | This would then be the place for your instance-specific properties. | ||
== Configuration == | == Configuration == |