842
edits
(+-headings, +-first section: bolding page title) |
Legoboyvdlp (talk | contribs) (Describe how to call functions of objects stored in a vector) |
||
Line 122: | Line 122: | ||
print(item); | print(item); | ||
} | } | ||
</syntaxhighlight> | |||
== Calling functions using vector objects == | |||
In order to call functions of objects stored in a vector, you need to refer to the wrapped Nasal vector itself: | |||
<syntaxhighlight lang="nasal"> | |||
var object = { | |||
char: '', | |||
new: func(char) { | |||
var objectChild = {parents:[object]}; | |||
objectChild.char = char; | |||
return objectChild; | |||
}, | |||
outputInfo: func() { | |||
print(me.char); | |||
} | |||
}; | |||
var objects = std.Vector.new([object.new('a')]); | |||
objects.vector[0].outputInfo(); | |||
</syntaxhighlight> | </syntaxhighlight> |
edits