Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Salesforce
  3. Question
Salesforce

Naming conventions for component, event, helper parameters in Lightning Components?

Asked by Anna Ball Jul 12, 2021 1.4K views 1 answer
Share

About this question

Examples variously call the component or cmp but there are so many references to the component or event or helper in typical code that I'm thinking it's time to reserve the single letter names for these as follows.(One precedent is Android's R class.) Controller:

({ showHelpMessageIfInvalid : function(c, e, h) { h.childOf(c).showHelpMessageIfInvalid(); }, checkValidity : function(c, e, h) { var child = h.childOf(c); if (typeof child.checkValidity === 'function') return child.checkValidity(); else return child.get("v.validity").valid; }, focus : function(c, e, h) { h.childOf(c).focus(); }, })
Helper:
({ childOf : function(c) { return c.find(c.get("v.multi") ? "dualListbox" : "select"); }, })
Here is another example from an internal discussion about what the code looks like when a method is decomposed into calls to other methods:
// Apex or Java void higher(String argument) { lower1(); lower2(lower3(argument)); } // Helper method with long names (that get in the way?) higherLevel : function(component, event, helper) { helper.lower1(); helper.lower2(helper.lower3(component.get(“v.argument"))); } // Helper method with short names (that help?) higherLevel : function(c, e, h) { h.lower1(); h.lower2(h.lower3(c.get("v.argument")); }

What is au ranaming conventions have you adopted in your Lightning Components for these parameters? What is naming convention in Salesforce?

Your answer

1 Answer

More Salesforce discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Salesforce Blogs

Guides, tips and career advice on Salesforce from JanBask experts.