Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update references to the is keyword and Std.is in accordance with the latest version of Haxe #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions comparing-haxe-and-actionscript/deep-dive/operators.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ The following operators are different between Haxe and ActionScript 3.0:

* `as`

You can convert `object as Type` to `Std.is(object, Type) ? cast(object, Type) : null` as a one-line replacement. However, there are usually more elegant ways to convert this code.
You can convert `object as Type` to `Std.isOfType(object, Type) ? cast (object, Type) : null` or `(object is Type) ? cast (object, Type) : null` as a one-line replacement. However, there are usually more elegant ways to convert this code.

If you know the type already, then you can use an unsafe cast:

Expand All @@ -129,7 +129,7 @@ The following operators are different between Haxe and ActionScript 3.0:
Lastly you can check the type of the object and return `null` in order to fully replicate the behavior of the `as` keyword from ActionScript 3.0:

```haxe
if (Std.is(object, Type))
if (Std.isOfType(object, Type)) // or (object is Type)
{
typedObject = cast object;
}
Expand All @@ -145,11 +145,11 @@ The following operators are different between Haxe and ActionScript 3.0:

* `instanceof`

The `Std.is` method can be used in most cases where `instanceof` is used in ActionScript 3.0.
The `Std.isOfType` method or the `is` keyword can be used in most cases where `instanceof` is used in ActionScript 3.0.

* `is`

Haxe provides `Std.is` rather than a special operator.
Prior to newer versions of Haxe, the `is` keyword did not work, and you had to use `Std.is`. It does work now, and it's worth noting `Std.is` has been deprecated in favor of `Std.isOfType`.

* `::`

Expand All @@ -161,7 +161,7 @@ The following operators are different between Haxe and ActionScript 3.0:

* `typeof`

Haxe provides a `Type.typeof` method that can be used to check the type, otherwise `Std.is` is common to determine if the object is of a certain type.
Haxe provides a `Type.typeof` method that can be used to check the type, otherwise `Std.isOfType` or the `is` keyword is common to determine if the object is of a certain type.

* `void`

Expand Down
11 changes: 7 additions & 4 deletions comparing-haxe-and-actionscript/deep-dive/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,15 @@ The Haxe programming language is designed to limit the number of keywords, so th

* `instanceof`

The ActionScript 3.0 keyword, `instanceof`, can be replaced with `Std.is`
The ActionScript 3.0 keyword, `instanceof`, can be replaced with `Std.isOfType` or the `is` keyword.

```haxe
trace (Std.is (sprite, DisplayObject));
trace (Std.is ("hello", String));
trace (Std.is (5, Int));
trace (Std.isOfType (sprite, DisplayObject));
trace (Std.isOfType ("hello", String));
trace (Std.isOfType (5, Int));
trace (sprite is DisplayObject);
trace ("hello" is String);
trace (5 is Int);
```

* `internal`
Expand Down
2 changes: 1 addition & 1 deletion glossary/cheat-sheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ type = Class (getDefinitionByName (name);
### Haxe

```haxe
if (Std.is (vehicle, Car)) {
if (Std.isOfType (vehicle, Car)) { // or (vehicle is car)

}

Expand Down
2 changes: 1 addition & 1 deletion glossary/error-messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ This might mean that you forgot a parenthesis in your code.

## Unexpected is

You can replace `Foo is Bar` with `Std.is (Foo, Bar)`
This shouldn't be a problem in newer versions of Haxe, but if you're still using Haxe 3 you can replace `Foo is Bar` with `Std.is (Foo, Bar)`. It's advised to update Haxe, though.

## Unexpected as

Expand Down