-
Notifications
You must be signed in to change notification settings - Fork 8
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
Scope Questions #16
Comments
I was originally thinking that the caller would set function a(block) {
block.call({
b: function(block) {
// ...
}
});
} Enabling a {
b {
}
} To be equivalent to: a(function() {
this.b(function() {
})
}) However, in this discussion I think I'm going back to my original formulation, which was to desugar things as: a {
b {
}
}
// equivalent to
a(function() {
b.call(this, function() {
})
}) In this formulation, select (foo) {
case (bar) { ... }
} WDYT? |
I addressed this in 1 and 2 of my first comment: |
@rwaldron Not if It still falls into the trap of making nested DSL calls ambiguous. |
I explicitly addressed this in number 3 of my first comment. |
Can you help me understand what you mean here? Specifically:
Can you help me understand what is (function() { "use strict"; function b() { console.log(this) } b.call({c: 1}) })()
// > {c: 1} Allows |
WRT
and
Yes, you are correct that if a user-defined function was bound per I think that's working as intended, in that's part of the contract for the functions that take block params in that they cannot assume that the bindings would be kept (and would rather point to the parent). |
Of course it does, because you used (function() { "use strict"; let b = () => { console.log(this) }; b.call({c: 1}) })()
// undefined
(function() { "use strict"; function f() { console.log(this) }; let b = f.bind({ d: 1}); b.call({c: 1}) })()
// { d: 1 }
I don't understand what you're saying here. Once
If you're telling me that block params can change the bound |
Yes. While I am supportive of the overall direction, @samuelgoto knows that I am against the specific |
I understand that if b is an arrow function or the result of fn.bind, then b.call() will have no effect. I think that, perhaps, what I am genuinely confused about, is that the feature is meant to be used primarily from the newly introduced syntax: a() { // <- this is a block param. neither an arrow function or a previously bound function
//
} Is your point that the function a(() => { "hello" });
function a(block) {
// I cannot assume that block.call() will have any effect because block may
// have been passed as an arrow function or as a previously bound function.
} Did I understand that correctly? Is that the point that you are trying to make? |
(oops, sorry for closing/reopening, pressed the wrong button) |
Just reporting back on this thread here with what I think was forward progress made in this thread. I'm generally in agreement with the desire to move away from the Just to give context, the use case that I think represents why we need a nesting mechanism is select (expr) {
when (cond) {
// execute this block if cond == expr.
}
} This was initially proposed as a series of nested Looking a bit into what this could look like with arrow functions, here is what we explored in the other thread:
For example, this is what you write instead: select (expr) {
::when(cond) {
// ... this gets executed if expr == cond ...
}
} Which gets transpiled as: select (expr, (__parent__) => {
__parent__.when(cond, (__parent__) => {
// .. gets executed if expr == cond ...
});
}) This gives function select(expr, block) {
block({
// this is the "when" implementation that gets accessed when called like ::when() {}
when(cond, inner) {
if (expr == cond) {
inner();
}
}
});
} Does that address some of the concerns raised here with regards to scoping and |
Similar discussion here too: |
Related to #24 |
EDIT:
The readme has been updated since this was first posted, however the changes made do not sufficiently address all of the scoping problems. Ref: 3280e50
Original follows the break
Re: the example from the readme:
What is
this
inside the callback function? In strict mode code, that desugaring has nothis
unless explicitly bound:The example does work with non-strict mode code, but also assumes that
b
was created via VariableStatement or FunctionDeclaration in the top level scope:b
was created as a LexicalDeclaration, it won't have a binding on globalthis
object:(2) falls down when the user defined functions have an explicit
this
object set:The text was updated successfully, but these errors were encountered: