Howto:Using Driver Hashes in Nasal: Difference between revisions

Jump to navigation Jump to search
Line 6: Line 6:
== What is a driver hash ==
== What is a driver hash ==
It's a conventional Nasal hash (imagine it like a namespace), which typically contains callbacks, i.e. functions. Driver hashes are usually nested in an outer hash, where a key can be used to look up the concrete implementation.
It's a conventional Nasal hash (imagine it like a namespace), which typically contains callbacks, i.e. functions. Driver hashes are usually nested in an outer hash, where a key can be used to look up the concrete implementation.
This is an empty hash named <code>myDriverHash</code>:
<syntaxhighlight lang="nasal">
var myDriverHash = {
};
</syntaxhighlight>
To populate the hash, we need to add keys to it - in this case, this can be best accomplisheed by adding strings to it, with a color specifying the value:
<syntaxhighlight lang="nasal">
var myDriverHash = {
"key1": "value"
};
</syntaxhighlight>
Different key/value pairs are separated using a comma:
<syntaxhighlight lang="nasal">
var myDriverHash = {
"key1": "some value",
"key2": "another value",
};
</syntaxhighlight>


== Problem ==
== Problem ==

Navigation menu