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
I don't get Function.apply #12
Comments
process.nextTick = (f, ...args) => {
uWS.nextTick(() => f(...args));
} the speard works also with arrays thats why this gets (arg1,arg2,arg3) |
but you got that already in your code apply would look like process.nextTick = (f, ...args) => {
console.log(this instanceof global) //=> true!
uWS.nextTick(() => f.apply(this, args));
} // this is in this case most time the global object of nodejs or in case of browser window
function withName() {
console.log(this instanceof global) //=> true!
uWS.nextTick(() => f.apply(this, args));
}.bind(this)
function withName() {
console.log(this instanceof global) //=> false!
console.log(this instanceof withName) //=> true!
uWS.nextTick(() => f.apply(this, args));
} in a JS file directly used bind(this) is eqal to not using bind(this) as arrow function don't have own scope importent side note () => arrow functions are using the outer scope as this so inside a named function the function is the scope if used directly the global object is the scope |
cant write all examples but if you point me to a file with some pseudo code i get it working for you with comments |
This is what I had: process.nextTick = (f, ...args) => uWS.nextTick(f.apply(...args)); Which is obviously wrong, but worked good enough for me not to find an issue until now. I thought this would solve it: process.nextTick = (f, ...args) => uWS.nextTick(() => {f.apply(...args);}); But it doesn't work..? If this works, that's like Golang and simple: process.nextTick = (f, ...args) => {
uWS.nextTick(() => f(...args));
} |
Apply signature: (context, args) So when you call f.apply(context, ars) it's same as: f.call(context, ...args) and f.bind(context)(...args) But if you don't need context setting (set internal f(...args) Hope this helps |
Yeah it helped, it works now at least. Thanks |
You're welcome. Thank you for UWS |
@alexhultman the code is wrong apply works directly with arrays don't use spread 3 dot operator when using apply it expects a array as secund argument f.apply(context, args)
f.call(context, ...args) |
How can I shorten this;
So that it works, presumably with apply, bind or any such thing. I can't get it working with apply.
The text was updated successfully, but these errors were encountered: