AS3 Tips – Uses of rarely used operator

Posted: September 14, 2011 in Adobe, Flex, Technology
Tags: , , ,

As a developer we are habitual to use commonly used approach in programming. There are several alternate and optimized way are also available and we need to give a chance to them as well. ActionScript 3 introduced various operators for specifying how to combine, compare, or modify the values of an expression. From these operators we used only few common operators. There are several rarely used operator are in list that may provide an alternate and optimized way of programming.

There is an operator named logical OR assignment (||=) , this is not in a frequently use. The use of ||= operator is it assigns expression1 the value of expression1 || expression2. First see the traditional approach with the use of conventional operator. See the below example.

Using If condition

Using logical OR assignment operator (||=) we can optimize this.

Using logical OR assignment (||=) operator

In the above example you can see that the complete logical IF statement is shrink into one single line. This operator work like if object is initialized then use the same otherwise assign the newly created object. Enjoy! and give a chance for this operator in your programming.

Comments
  1. Vijay Kumar says:

    Good work….

    Keep posting this type of post

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s