Created
March 27, 2015 19:00
-
-
Save ThomasBurleson/37693392a8bf7f4648e4 to your computer and use it in GitHub Desktop.
Code improvements using ternary operators
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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