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

Don't patch string prototype #33

Open
felixfbecker opened this issue Sep 15, 2017 · 7 comments
Open

Don't patch string prototype #33

felixfbecker opened this issue Sep 15, 2017 · 7 comments

Comments

@felixfbecker
Copy link

Patching prototypes of global objects is a bad practice. Would it be possible to get a version of this module that just exports the scoring function, with a UMD wrapper so it can be used in a CommonJS environment? That would also make it possible to pass the function directly to array.sort()

@thereis
Copy link

thereis commented Dec 6, 2017

const score = require('string_score')

let word = "Hello World"

console.log(word.score("Hell"))

@joshaven
Copy link
Owner

joshaven commented Dec 6, 2017 via email

@thereis
Copy link

thereis commented Dec 6, 2017

Sorry for the typo hehe

@DannyvanderJagt
Copy link

This would be nice! Planning on using this lib in a large production app but would like to get rid of the prototype patching. Created a local version which doesn't have the prototype patching, we could do an import like:

// Usage without prototype patching
const score = require('string_score/no-prototype')

const word = "Hello World"

console.log(score(word, "Hell")
// Normal usage with prototype patching
 require("string_score");

This will allow us to release a new non-breaking version of this lib.
Got a local version ready to go, are you interested in me doing a PR for this?

@joshaven What's your opinion on this topic?

@joshaven
Copy link
Owner

joshaven commented Jan 4, 2018 via email

@DannyvanderJagt
Copy link

Thanks! Sounds good. I will make a PR so you can take a look at it, maybe it helps. It can be quite a small change.

@BuonOmo
Copy link

BuonOmo commented Dec 18, 2019

@DannyvanderJagt could you push your code on a PR? At least it would be accessible to the community!

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

5 participants