I recently came across the idea that it would be great(/easy/convenient) to define dynamic properties on the Javascript String prototype, so you can use your string literals and variables kinda like it works in ruby. Take this example:
// Using ES2015 syntax features
Object.defineProperty(String.prototype, 'ucFirst', {
get() {
return this.charAt(0).toUpperCase() + this.substr(1);
}
});
This way you'd be able to use your strings like this:
"foo".ucFirst // "Foo"
"lorem ipsum dolor sit amet".ucFirst // "Lorem ipsum dolor sit amet"
$t('some_i18nized_string').ucFirst // You get it
I can already imagine a whole bunch of handy applications for that, but I am not sure about it. It works, but I am kinda afraid that it might be bad practice and it kinda smells funny.
Let me know what you think about it.