Skip to main content

method

Method calls in Soul allow you to invoke functions that are associated with objects, classes, or built-in types. They use dot notation to access and call methods on various data types and objects.

Basic Method Calls

Call methods on objects using dot notation:

Method Calls with Arguments

Pass arguments to methods:

String Method Calls

Common string methods:

Array/List Method Calls

Common array methods:

Map/Object Method Calls

Common map methods:

Chained Method Calls

Chain multiple method calls together:

Method Calls on Class Instances

Call methods on class instances:

Static Method Calls

Call static methods on classes:

Method Calls with Variable Arguments

Methods that accept variable numbers of arguments:

Method Calls with Callback Functions

Pass functions as arguments to methods:

Method Calls on Built-in Types

Call methods on built-in types:

Async Method Calls

Call asynchronous methods:

Method Calls with Error Handling

Handle errors in method calls:

Dynamic Method Calls

Call methods dynamically using variables:

Method Calls in Expressions

Use method calls within expressions:

Method Calls with Complex Arguments

Pass complex expressions as arguments:

Method Calls on Null/Undefined

Handle null object method calls:

Method Call Performance

Optimize method calls:

Best Practices

  1. Check object existence: Verify objects exist before calling methods
  2. Handle errors: Use try-catch for risky method calls
  3. Use meaningful names: Choose descriptive method names
  4. Chain appropriately: Use method chaining for fluent interfaces
  5. Validate arguments: Check method arguments before use
Method calls are fundamental to object-oriented programming in Soul, providing a clean and intuitive way to interact with objects and their functionality.