简体   繁体   中英

Dollar Sign with Dot Notation?

In Javascript (Titanium), what does the dollar sign mean when it's used in place of the variable name?

$.result.text = e.name+': $'+e.price;

Below is an example of a Titanium 'fireEvent', where a view is receiving data from an object, assigned to the variable name $.result.text . It appears to be dot notation, but I'm not sure what variable the dollar sign represents.

Is this a wild card character or reference to the receiving object? I've tried to research more info on this, but most searches come back with jquery or php type info. I'm not using jquery, so not sure how it would apply here.

Here is more detail from the example I'm referencing:

When the table view is clicked, the following code is executed.

Ti.App.fireEvent('MVC:tab:itemSelected', {
         name:e.rowData.title,
         price:e.rowData.price
     });

The following is the corresponding event listener in detail.js:

   Ti.App.addEventListener('MVC:tab:itemSelected', function(e) {
     $.result.text = e.name+': $'+e.price;
});

The $ sign in Titanium is the current window object. So your $ object includes a result object which has a text property. So you are right, it is dot notation.

Basic example for the $ reference (from the official docs , which are quite good!):

XML:

<Alloy>
    <Window>
        <Widget src="mywidget" id="foo" name="foo" />
    </Window>
</Alloy>

JS:

$.index.open();
$.foo.myMethod();

For anyone else looking for the specific answer:

'$.' Identifies UI elements in the controller (prefixed with '$.') and style sheet (prefixed with '#'). IDs should be unique per view but are not global, so multiple views can have components with the same ID.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM