Call an object method: Difference between revisions
Content added Content deleted
(added go) |
(added smalltalk) |
||
Line 123: | Line 123: | ||
// Instance |
// Instance |
||
[myInstance method:someParameter]; |
[myInstance method:someParameter]; |
||
// Method with multiple arguments |
|||
[myInstance methodWithRed:arg1 green:arg2 blue:arg3]; |
|||
// Method with no arguments |
|||
[myInstance method];</lang> |
|||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
Line 206: | Line 212: | ||
# Calling a method with no parameters |
# Calling a method with no parameters |
||
myInstance.anotherMethod</lang> |
myInstance.anotherMethod</lang> |
||
=={{header|Smalltalk}}== |
|||
In Smalltalk, calling an instance method is sending a message to an instance, and calling a class method is sending a message to a class object. Class methods are inherited through inheritance of classes. All messages (whether sent to a normal object or class object) are resolved dynamically at runtime, hence there are no "static" methods. |
|||
<lang smalltalk>" Class " |
|||
MyClass method:someParameter . |
|||
" or equivalently " |
|||
foo := MyClass . |
|||
foo method:someParameter . |
|||
" Instance " |
|||
myInstance method:someParameter . |
|||
" Method with multiple arguments " |
|||
myInstance methodWithRed:arg1 green:arg2 blue:arg3 . |
|||
" Method with no arguments " |
|||
myInstance method . |
|||
" Operator method " |
|||
myInstance + somethingElse .</lang> |
|||
=={{header|Tcl}}== |
=={{header|Tcl}}== |