Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding methods to the String Prototype? #6

Closed
d1b1 opened this issue Feb 27, 2014 · 3 comments
Closed

Adding methods to the String Prototype? #6

d1b1 opened this issue Feb 27, 2014 · 3 comments

Comments

@d1b1
Copy link

d1b1 commented Feb 27, 2014

Afternoon. Great module. I was wondering if there was any thought of adding these methods to the String prototype to enable str.titleCase()? etc?

@blakeembrey
Copy link
Owner

It's unlikely, I disagree with ever extending a built-in prototype. If you want you can just assign it yourself and write a wrapper. E.g.

var changeCase = require('change-case');

for (var key in changeCase) {
  String.prototype[key] = function () {
    return changeCase[key](this);
  };
}

@d1b1
Copy link
Author

d1b1 commented Feb 27, 2014

I value perspective. Would you be willing to share why you avoid extending? Is it because other modules might collide and cause issues? Thanks!

@blakeembrey
Copy link
Owner

Yeah, no problem. There are a couple of things and collisions are definitely valid. It basically comes down to if I wanted to extend someone elses code with my own - I would subclass it to ensure greater compatibility. It also means that other people that use the code aren't startled when this random bit of code is inside something they are using.

Although this isn't as specific as other things, I believe the rule should be fully enforced everywhere. That way no one has any surprises and the original authors can continue building up their code without having to worry about downstream consumers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants