Interview Questions – Lightning Framework – Part 8 – Lightning Locker, Aura Methods

Interview Questions – Lightning Framework – Part 8 – Lightning Locker, Aura Methods

Checkout earlier posts in interview question series to read previous questions.

62. What are aura:methods, why we use those?

Use  to define a method as part of a component’s API. This enables you to directly call a method in a component’s client-side controller instead of firing and handling a component event. Using  simplifies the code needed for a parent component to call a method on a child component that it contains.

Use aura:method to communicate down the containment hierarchy. For example, a parent component calls an aura:method on a child component that it contains.

<aura:method name="sampleMethod" action=“{!c.controllerAction}”
  description="Sample method with parameters">
    <aura:attribute name="param1" type="String" default="parameter 1"/>

63. Can aura method return a value?

Yes, aura method can return values similar to any other JavaScript method. Use return statement in controller action of aura method to return a value.

64. What are different ways to communicate between components?

  • If component hierarchy is same
    • Parent to Child Communication-
      • Attributes can be used to create a binding between parent and child.
      • Aura methods can be used if parent component wants to access a function in child component
      • Application events can be used but not preferred.*
    • Child to Parent Communication-
      • Attributes can be used to create a binding between parent and child.
      • Component event can be used to perform functionality in parent component based on an event in child component.
      • Application events can be used but not preferred.*
  • If components are in different hierarchy-
    • Application events is the best solution for this type of communication.
    • Shared javascript resources can be used.

65. What is Lightning Locker?

Lightning Locker is a powerful security architecture for Lightning components. Lightning Locker enhances security by isolating Lightning components that belong to one namespace from components in a different namespace. Lightning Locker also promotes best practices that improve the supportability of your code by only allowing access to supported APIs and eliminating access to non-published framework internals.

Also Read: Lightning Locker Explained with example

66. What is DOM Access containment in Lightning Locker?

A component can only traverse the DOM and access elements created by a component in the same namespace. This behavior prevents the anti-pattern of reaching into DOM elements owned by components in another namespace.

67. What are proxy objects?

Lightning Locker uses the standard JavaScript Proxy object to filter a component’s access to underlying JavaScript objects. The Proxy object ensures that a component only sees DOM elements created by a component in the same namespace.

When a component creates a JavaScript object, Lightning Locker returns the raw JavaScript object. When Lightning Locker filters the object, it returns a Proxy object. Some scenarios where Lightning Locker filters an object and returns a Proxyobject are:

  • Passing an object to a component in a different namespace.
  • Passing an object from a component on API version less than 40.0 to the method of a component on API version greater than or equal to 40.0.
  • Calling cmp.get() to retrieve an attribute value that you set with the value of a native JavaScript object or array. The object or array isn’t filtered when it’s originally created

When you access these objects, Lightning Locker returns a Proxy object.

68. What are secure wrappers?

For security, Lightning Locker restricts the use of global objects by hiding an object or by wrapping it in a secure version of the object. For example, the secure version of window is SecureWindow. Locker intercepts calls to window and uses SecureWindow instead. Some methods and properties have different behavior or aren’t available on the secure objects.

Lightning Locker also replaces instances of other objects, such as components and events, with secure wrapped versions like SecureAura, SecureComponent, SecureComponentRef, SecureDocument, SecureElement, SecureObject, SecureWindow.

69. Does lightning locker affects Salesforce classic as well?

Lightning Locker enforces security and best practices for custom Lightning components you use in:

  • Lightning Experience
  • Salesforce app
  • Lightning Communities
  • Flows
  • Standalone apps that you create (for example,
  • Any other app where you can add a custom Lightning component, such as Salesforce Console in Lightning Experience
  • Lightning Out

Lightning Locker doesn’t affect the following except for usage of Lightning components in Visualforce in these contexts:

  • Salesforce Classic
  • Visualforce-based communities
  • Any apps for Salesforce Classic, such as Salesforce Console in Salesforce Classic

70. How can one disable Lightning Locker for an Aura Component?

You can disable Lightning Locker for a component by setting API version 39.0 or lower for the component. If a component is set to at least API version 40.0, Lightning Locker is enabled.

Read Also:

Manish Choudhari

I am a certified Salesforce Application & System Architect and Developer working on Salesforce Technology since 2014. Currently, I have 14 Salesforce certifications along with OCPJP (Oracle Certified Profession JavaSE6 Programmer) working in Hyderabad as a Technical Engineer. Writing technical blogs, learning new technologies and frameworks and sharing knowledge is my hobby.

Leave a Reply

Close Menu