1.21 gigawatts
1.21 gigawatts

Reputation: 17770

What does the $ in property name mean in ActionScript 3 (or JavaScript)

I saw this code recently,

    public function CursorManager($target:InteractiveObject, $cursor:String) {
        _target=$target;
        _cursor=$cursor;
        _target.addEventListener(MouseEvent.ROLL_OVER, onOver);
        _target.addEventListener(MouseEvent.ROLL_OUT, onOut);
    }

Why is this person using the $ in the parameter $target? Does it hold any significant meaning? I've seen this in JavaScript as well.

UPDATE:
Is it possible it was used to denote static or constant variable? It does not appear to be used as static in this example.

UPDATE 2:
I found some code in the Flex UIComponent class that uses $width, $height. I've added an answer.

Upvotes: 1

Views: 180

Answers (3)

1.21 gigawatts
1.21 gigawatts

Reputation: 17770

As Max stated, "the answer is NO, it doesn't hold any significant meaning. It is done for convenience only." but I want to add more. It is not treated any differently by the compiler (as far as I know) but in Flex it is used to signify a base property, it's final and cannot be overridden that is a reflection of a native player implementation.

For example, in the property $scaleX it states:

/**
 *  This property allows access to the Player's native implementation
 *  of the <code>scaleX</code> property, which can be useful since components
 *  can override <code>scaleX</code> and thereby hide the native implementation.
 *  Note that this "base property" is final and cannot be overridden,
 *  so you can count on it to reflect what is happening at the player level.
 */

The $width property is the same:

/**
 *  @private
 *  This property allows access to the Player's native implementation
 *  of the 'width' property, which can be useful since components
 *  can override 'width' and thereby hide the native implementation.
 *  Note that this "base property" is final and cannot be overridden,
 *  so you can count on it to reflect what is happening at the player level.
 */

mx_internal final function get $width():Number
{
    return super.width; // UIComponent extends FlexSprite which extends Sprite
}

All of the properties that begin with $ in the UIComponent class reflect these attributes.

Upvotes: 0

Max Gram
Max Gram

Reputation: 695

In this example I would say author uses $ prefix to identify variable that comes from outside (function parameter) and prefix _ to identify variable that belongs to the this function or entire class.

So the answer is NO, it doesn't hold any significant meaning. It is done for convenience only. You may want to look into code naming conventions to learn more about that.

Upvotes: 4

Philipp Kyeck
Philipp Kyeck

Reputation: 18830

When I code JavaScript I use this notation for jQuery-Objects like this:

var $target = $(event.target);
$target.hide();

Others may use this differently.

Upvotes: 2

Related Questions