Concepts or coding lessons of Salesforce that you can implement easily

Lightning Locker Service In Salesforce: This Is What Professionals Do

The Lightning LockerService architectural layer enhances security by isolating individual Lightning components in their own namespace and enforcing coding best practices. 

LockerService prevents security issues and unsupported practices when you develop your own Lightning components or use third-party libraries in your Lightning components.

LockerService enforces security in:
  • Lightning Experience
  • Salesforce
  • Template-based Communities
  • Standalone apps that you create (for example, myApp.app)
  • Lightning Out, including Lightning Components for Visualforce

Learn Learning Salesforce Lightning Application Development to accelerate your Career with Salesforce!!! 

Locker Service 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
LockerService enforces several security features in your Lightning code, including:

1. JavaScript ES5 Strict Mode Enforcement is implicitly enabled
You don't need to specify "use strict" in your code. Enforcement includes a declaration of variables with the var keyword and other JavaScript coding best practices. Any libraries that your components use must also work in strict mode.

2. 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.

Become EXPERT in APEX with Salesforce Lightning.

3. LockerService applies restrictions to global references
You can access intrinsic objects, such as Array. LockerService provides secure versions of non-intrinsic objects, such as a window. The secure object versions automatically and seamlessly control access to the object and its properties.

4. Enforcement of access to published, supported JavaScript API framework methods only
These methods are published in the reference doc app at https://yourDomain.lightning.force.com/auradocs/reference.app. Previously, private and unsupported methods were accessible, which exposed your code to the risk of breaking when these methods were changed or removed.

Check out below to more about Lightning LockerService