ThomasBurleson
3/27/2015 - 7:00 PM

Code improvements using ternary operators

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();
}