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

prototype methods #13

Closed
DarkPark opened this issue Jul 6, 2015 · 2 comments
Closed

prototype methods #13

DarkPark opened this issue Jul 6, 2015 · 2 comments

Comments

@DarkPark
Copy link

DarkPark commented Jul 6, 2015

Is there a reason why some of your methods in prototype and some not?

@taylorhakes
Copy link
Owner

Yes, prototype methods are visible to the outside world, essentially public. It is common pattern to put private methods on prototype, but prefix with an underscore. i.e. Promise.prototype._privateFunc.

Since this library is a polyfill, I tried to make it as close to the built-in Promise as possible. The built-in Promise doesn't expose any underscore methods.

You can make true private methods using a closure and calling it like fn.apply(this, args). You still get the same performance benefits as the prototype methods, but the functions are not exposed to the outside world on the prototype. Does that make sense?

@DarkPark
Copy link
Author

DarkPark commented Jul 7, 2015

thank you for detailed explanation
I haven't check the native Prototype global object to see the same public methods
so now it's clear

@DarkPark DarkPark closed this as completed Jul 7, 2015
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