samedi 14 février 2015

Custom JavaScript String Placeholders | Format Specifiers


Ok guys so I'm trying to truncate my workload by adding a custom Format Specifier to String.prototype. I've little experience with specifiers in the past other than in chromes console. But I like the idea of them and couldn't believe it when I read an article at MDN stating that JavaScript doesn't support the feature.


So I said, I'll construct my own version called .format(). Now, I'm looking to add another feature and I'm stuck.


Is it possible to do something like this:



str = "abc123¦I'm Formatted Before I'm Parsed!".format;


Where ¦ is a unique separator and abc123 references a data object variable.


On Instantiation of the object, I suppose before it is given the string prototype, .format, now a get method is called, the string is split at the separator, parsed according to the data object reference abc123, eg: {'abc123':...}, then returned to str as it's declaration.





Aucun commentaire:

Enregistrer un commentaire