Last active
June 9, 2018 14:36
-
-
Save mcavaliere/1c3dfb95ccbe29761543 to your computer and use it in GitHub Desktop.
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
// Less Coupled | |
var CountrySelectClass = function() { | |
var countriesIveBeenTo = { | |
'BE': 'Belgium', | |
'CR': 'Costa Rica', | |
'IT': 'Italy', | |
'US': 'United States of America', | |
'UK': 'United Kingdom' | |
}; | |
this.init = function(selector) { | |
this.$el = $(selector); | |
$.each(countriesIveBeenTo, function(val, text) { | |
this.$el.append( | |
$('<option value="' + val + '">' + text + '</option>') | |
); | |
}.bind(this)); | |
this.$el.change(function() { | |
console.log('Selected country: ' + this.$el.find(':selected').text()); | |
}.bind(this)); | |
}; | |
}; | |
$(function() { | |
$(document.body).append( $('<select id="countries"></select>') ); | |
var csInstance = new CountrySelectClass(); | |
csInstance.init("#countries"); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment