Last active
December 10, 2015 02:09
-
-
Save tangrammer/4365658 to your computer and use it in GitHub Desktop.
dispatch table pattern to obtain the localized date printer for one person Note that the returned function expect the date in its closure scope "this.date" It use date_format.js lib to augmenting Date function with format method.
Obtained from http://jsfiddle.net/phZr7/1/
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
/* functions printers outside for better reuse*/ | |
var date_printer={ | |
//US = United States, UK = United Kingdom, AU = Australia | |
US: function(){return "US: "+this.date.format("mm/dd/yy");}, | |
UK: function(){return "UK: "+this.date.format("dd/mm/yy");}, | |
AU: function(){return "AU: "+this.date.format("dd/mm/yy");} | |
}; |
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
var context={date:"1976-06-13"}; | |
var us_printer=date_printer.US; | |
us_printer.call(context); // return US: 06/13/76 | |
var au_printer=date_printer.AU; | |
au_printer.call(context); // return AU: 13/06/76 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment