20,741
edits
Line 541: | Line 541: | ||
You could even implement an overloaded function that creates arrays/vectors of objects. | You could even implement an overloaded function that creates arrays/vectors of objects. | ||
A simple generic constructor can be expressed in a very succinct fashion: | |||
<syntaxhighlight lang="php"> | |||
# a new function with an implicit arg parameter that simply returns a new hash with the parents field set to all arguments provided | |||
var new = func return { parents:arg }; | |||
var Position3D = {x:0.0, y:0.0, z:0.0}; | |||
var p = new( Position3D ); | |||
</syntaxhighlight> | |||
Now, let's imagine you want to add another member function to print a certain field's value, such as "number". | Now, let's imagine you want to add another member function to print a certain field's value, such as "number". |