Created
October 18, 2009 22:49
-
-
Save ChrisMissal/212914 to your computer and use it in GitHub Desktop.
using a ternary operator to call one of two functions
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
// One of the reasons I like JavaScript: | |
function toggleTrait(trait, iconName) { | |
// some ugly code :) | |
((hasTrait) ? addIcon : removeIcon)(iconBar, iconName); | |
} | |
function addIcon(iconBar, iconName) { | |
iconBar.append($("<img/>").attr("src", "img/" + iconName + ".png")); | |
} | |
function removeIcon(iconBar, iconName) { | |
var selector = "[src*='" + iconName + "']"; | |
iconBar.children(selector).replaceWith(''); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment