With

From Sputnik Wiki
Jump to: navigation, search

Contents

With

Description

Allows the execution of code within a block as if it was taking place within the class itself so there is no need for -> and so on.

With ( <class> )
{
    statements
    ...
}

Parameters

class

A class to use.

Remarks

None.

Example

Example on a simple string:

// Define a new class
Class Test
{
	my $X;
	my $Y;
	Function Hello()
	{
		say "Hello";
	}
};
 
// Create new intance of the class
$t = new Test();
 
// Use With to set the variables of the class
// and call functions within the class
// without having to do ->
With($t)
{
	$X = 10;
	$Y = 20;
	Hello();
}
// Print the content of the class so we can view it
printr($t);
// Prints:
// Hello
// {CLASS:test;ID:5}
// {
//         [x] => 10
//         [y] => 20
// }
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox