Howto:Start using vectors and hashes in Nasal: Difference between revisions

Jump to navigation Jump to search
m
m (→‎A hash based version (recommended): remove untested brain fart ... as per: http://forum.flightgear.org/viewtopic.php?f=71&t=23204&p=211657#p211638)
Line 599: Line 599:


Sometimes, you'll work with classes that do not have any custom constructor functions - but you can easily create a generic constructor, too:
Sometimes, you'll work with classes that do not have any custom constructor functions - but you can easily create a generic constructor, too:
<syntaxhighlight lang="php">
var new = func(obj) {
    return {parents:obj};
}
</syntaxhighlight>
As long as '''obj''' is a vector of hashes, it can be simply invoked like this:
<syntaxhighlight lang="php">
var p = new( Position3D );
</syntaxhighlight>
Now, once you remember that Nasal implicitly has an '''arg''' vector for its arguments, the whole thing can be simplified like this:


<syntaxhighlight lang="php">
<syntaxhighlight lang="php">

Navigation menu