Skip to content

Instantly share code, notes, and snippets.

@ThomasBurleson
Created March 27, 2015 19:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ThomasBurleson/37693392a8bf7f4648e4 to your computer and use it in GitHub Desktop.
Save ThomasBurleson/37693392a8bf7f4648e4 to your computer and use it in GitHub Desktop.
Code improvements using ternary operators
// Classic solution
function getLabel () {
//-- if label provided, then send label
if (attr.label) return attr.label;
//-- otherwise, we have to search for the `md-tab-label` element
var label = element.find('md-tab-label');
if (label.length) return label.html();
//-- otherwise, we have no label.
return element.html();
}
// Improved with ternaries
/**
* If label provided, then send label
* otherwise, we have to search for the `md-tab-label` element
* otherwise, we have no label.
*/
function getLabel () {
if (attr.label ) return attr.label;
var label = element.find('md-tab-label');
return (label && label.length) ? label.html() : element.html();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment