Posts Tagged ‘Optimize’

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.