-
Notifications
You must be signed in to change notification settings - Fork 7
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
Should this also censor .name
?
#2
Comments
Good question. I think no since you can already do censorship of name using |
@domenic I'm not sure "can already do this" is sufficient to make this decision. Remember you could say the same about hiding On a related note, I want to consider @domenic Can we re-open for further discussion? |
Happy to reopen for further discussion, but I'm a bit unsure on the use case here. As you might imagine, I'm working on analogy to built-ins, whose implementation details are hidden in the way I'm hoping that our userland libraries can attain. There:
Can you say more about the case you're concerned about, perhaps with code samples? |
imo the number of mandatory parameters is an inextricable part of the public API. |
The original motivation for this proposal included both reliably polyfilling built-ins and easing refactoring/encapsulation. Function names being provided gives unwanted extra implementation information: (function(){
function a() { ... }
function b() { ... }
f(someDecision() ? a : b)
}()) I don't want (function(){
function meaningfulNameA() { ... }
function meaningfulNameB() { ... }
f(someDecision() ? meaningfulNameA : meaningfulNameB)
}()) Similarly, if my library provides an API: export function doSomething(a, b) { ... }
export function doSomethingElse(a, b) { ... } I cannot refactor that API to use default parameters or rest parameters, even if they would otherwise provide the same functionality. export function doSomething(a, b = 0) { ... }
export function doSomethingElse(a, ...b) { ... } So in these examples I've shown that implicitly providing It's important to note, though, that this goal conflicts to some degree with the polyfilling goal since an accurate polyfill would want to match the |
Yes, I agree there's a conflict of goals here.
My take is that passing functions from a library to outside code as callbacks, and not wanting the caller to know these function names, is more rare than a library exposing methods/classes/functions to outside code, and wanting that outside code to know those function names. So I am OK making the callback case require wrapping, and not automatically get censored via the "hide implementation" pragma.
This case is a more stark example of conflict. In particular, you're claiming that the length property of the function is just an implementation detail, whereas from my perspective (and @ljharb's) it's part of the public API. To be clear, I don't mean that it's public API in the trivial sense of "it's publicly exposed". A function's (This is clearest for So overall, to me it makes more sense to be conservative here, and focus on the intersection use cases. Maybe we want a second pragma for .length/.name hiding? |
Okay yeah, it seems they'd have to be separated. I think this would be an interesting topic for the next time this proposal is presented to committee. |
The committee chose not to add a convenient way to do this. |
@michaelficarra can you give some information about why the committee decided this? The last notes i found on this were here: https://github.com/tc39/notes/blob/master/meetings/2019-03/mar-27.md#function-implementation-hiding-stage-2-update but they are a bit hard to follow. Also the proposal was recently discussed here https://github.com/tc39/notes/blob/master/meetings/2019-07/july-24.md#update-on-function-implementation-hiding but it doesnt seem to be related to this |
@codehag Sorry, I don't have the details anymore. I can bring it up again at the next presentation to committee. But I haven't advocated for this feature since we decided which use cases we would consider for this proposal. Hiding name/length is unwanted for the built-in polyfilling use case, which would complicate the solution. There's also a fairly easy way to do it today using |
My inclination is no but it seems similar in that the name might be used in strange ways by a caller prevent changing the name of the original function.
For example if we have an object like
{ render() { ... }, update() { ... } }
then if a consumer of that object uses the.name
property as a key then the object could never be changed to{ render: definedOutsideObject, update: debounce(function update() {}) }
.I don't know if this has even been in common usage like it was for parameter parsing in angular so it might not be worthwhile.
The text was updated successfully, but these errors were encountered: