---
schema_version: "1"
id: 7225289479c6aa91092d5635cb79b113f11ec0d21efda2ca77b6d2fc190fcd22
title: Namespace Usage Examples and Reference
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/platform/aura-platform/guides/aura/namespaces/namespace-using-reference.md
canonical_url: https://developer.salesforce.com/docs/platform/aura-platform/guide/namespace-using-reference.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: bb38a9c02e73fe73c7ca8bba9dd7d35598a0f0421397efc1d631f4ecffa85361
products:
  - Lightning Aura Components Developer Guide
  - Platform Developer Content
---

# Namespace Usage Examples and Reference

This topic provides examples of referencing components, objects, fields, and so on, in Aura components code.

Examples are provided for the following.

-   Components, events, and interfaces in your organization
-   Custom objects in your organization
-   Custom fields on standard and custom objects in your organization
-   Server-side Apex controllers in your organization
-   Dynamic creation of components in JavaScript
-   Static resources in your organization

## Organizations with No Namespace Prefix Set

The following illustrates references to elements in your organization when your organization doesn’t have a namespace prefix set. References use the default namespace, `c`, where necessary.

|Referenced Item|Example|
|---------------|-------|
|Component used in markup|`<c:myComponent />`|
|Component used in a system attribute|`<aura:component extends="c:myComponent"> ``<aura:component implements="c:myInterface">`|
|Apex controller|`<aura:component controller="ExpenseController">`|
|Custom object in attribute data type|`<aura:attribute name="expense" type="Expense__c" />`|
|Custom object or custom field in attribute defaults|See the example after this table.|
|Custom field in an expression|`<lightning:inputNumber type="number" value="{!v.newExpense.Amount__c}" label=… />`|
|Custom field in a JavaScript function|See the example after this table.|
|Component created dynamically in a JavaScript function|See the example after this table.|
|Interface comparison in a JavaScript function|`aCmp.isInstanceOf("c:myInterface")`|
|Event registration|`<aura:registerEvent type="c:updateExpenseItem" name=… />`|
|Event handler|`<aura:handler event="c:updateExpenseItem" action=… />`|
|Explicit dependency|`<aura:dependency resource="markup://c:myComponent" />`|
|Application event in a JavaScript function|`var updateEvent = $A.get("e.c:updateExpenseItem");`|
|Static resources|`<ltng:require scripts="{!$Resource.resourceName}" styles="{!$Resource.resourceName}" />`|

Example of a custom object or custom field in attribute defaults:

```html
<aura:attribute name="newExpense" type="Expense__c"
    default="{ 'sobjectType': 'Expense__c',
               'Name': '',
               'Amount__c': 0,
               …
    }" />
```

Example of a custom field in a JavaScript function:

```javascript
updateTotal: function(component) {
    …
    for(var i = 0 ; i < expenses.length ; i++){
        var exp = expenses[i];
        total += exp.Amount__c;
    }
    …
}
```

Example of a component created dynamically in a JavaScript function:

```javascript
var myCmp = $A.createComponent("c:myComponent", {},
    function(myCmp) { }
);
```

## Organizations with a Namespace Prefix

The following illustrates references to elements in your organization when your organization has set a namespace prefix. References use an example namespace `yournamespace`.

|Referenced Item|Example|
|---------------|-------|
|Component used in markup|`<yournamespace:myComponent />`|
|Component used in a system attribute|`<aura:component extends="yournamespace:myComponent"> ``<aura:component implements="yournamespace:myInterface">`|
|Apex controller|`<aura:component controller="yournamespace.ExpenseController">`|
|Custom object in attribute data type|`<aura:attribute name="expenses" type="yournamespace__Expense__c[]" />`|
|Custom object or custom field in attribute defaults|See the example after this table.|
|Custom field in an expression|`<lightning:input type="number" value="{!v.newExpense.yournamespace__Amount__c}" label=… />`|
|Custom field in a JavaScript function|See the example after this table.|
|Component created dynamically in a JavaScript function|See the example after this table.|
|Interface comparison in a JavaScript function|`aCmp.isInstanceOf("yournamespace:myInterface")`|
|Event registration|`<aura:registerEvent type="yournamespace:updateExpenseItem" name=… />`|
|Event handler|`<aura:handler event="yournamespace:updateExpenseItem" action=… />`|
|Explicit dependency|`<aura:dependency resource="markup://yournamespace:myComponent" />`|
|Application event in a JavaScript function|`var updateEvent = $A.get("e.yournamespace:updateExpenseItem");`|
|Static resources|`<ltng:require scripts="{!$Resource.yournamespace__resourceName}" styles="{!$Resource.yournamespace__resourceName}" />`|

Example of a custom object or custom field in attribute defaults:

```html
<aura:attribute name="newExpense" type="yournamespace__Expense__c"
    default="{ 'sobjectType': 'yournamespace__Expense__c',
               'Name': '',
               'yournamespace__Amount__c': 0,
               …
    }" />
```

Example of a custom field in a JavaScript function:

```javascript
updateTotal: function(component) {
    …
    for(var i = 0 ; i < expenses.length ; i++){
        var exp = expenses[i];
        total += exp.yournamespace__Amount__c;
    }
    …
}
```

Example of a component created dynamically in a JavaScript function:

```javascript
var myCmp = $A.createComponent("yournamespace:myComponent",
    {},
    function(myCmp) { }
);
```

