Call an object method: Difference between revisions
Content added Content deleted
(→{{header|ALGOL 68}}: more notes) |
No edit summary |
||
Line 456: | Line 456: | ||
IO.puts(obj |> ObjectCall.concat("Hello ", "World!")) |
IO.puts(obj |> ObjectCall.concat("Hello ", "World!")) |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
=={{header|EMal}}== |
|||
{{trans|Wren}} |
|||
<syntaxhighlight lang="emal"> |
|||
type MyClass ^|we are defining a new data type and entering in its static context|^ |
|||
fun method = void by block do writeLine("static method called") end |
|||
model ^|we enter the instance context|^ |
|||
fun method = void by block do writeLine("instance method called") end |
|||
end |
|||
type CallAnObjectMethod |
|||
var instance = MyClass() ^|creating an instance|^ |
|||
instance.method() |
|||
MyClass.method() |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
instance method called |
|||
static method called |
|||
</pre> |
|||
=={{header|Factor}}== |
=={{header|Factor}}== |
||
In Factor, there is no distinction between instance and static methods. Methods are contained in generic words and specialize on a class. Generic words define a <i>method combination</i> so methods know which object(s) to dispatch on. (But most methods dispatch on the object at the top of the data stack.) Under this object model, calling a method is no different than calling any other word. |
In Factor, there is no distinction between instance and static methods. Methods are contained in generic words and specialize on a class. Generic words define a <i>method combination</i> so methods know which object(s) to dispatch on. (But most methods dispatch on the object at the top of the data stack.) Under this object model, calling a method is no different than calling any other word. |