You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/**
* Takes `lambda` function and returns a method. When returned method is
* invoked, it calls the wrapped `lambda` and passes `this` as a first argument
* and given arguments as the rest.
*
* @params {Function} lambda
* @returns {Function}
*/
function method (lambda) {
return function () {
return lambda.apply(null, [this].concat(Array.prototype.slice.call(arguments, 0)));
};
}
exports.method = method;
you pass null as the first argument to apply. Why would you not pass this as the first argument so that you would have the ability to use this in the wrapped functions and have it point to the Poet instance. I'm aware you are making sure that the poet instance is always the first argument in the wrapped functions (so this would be redundant) but would it hurt any? Wouldn't having this point to GLOBAL be risky?
I am more trying to understand why than anything else.
The text was updated successfully, but these errors were encountered:
Just a functional helper I've picked up -- it does exactly what you said it does, just moving this to the first argument. It's only used internally for attaching methods on poet, leaving for more transparent unit testing (although I'm not sure if these functions are tested directly like that)
In your method util,
you pass
null
as the first argument to apply. Why would you not passthis
as the first argument so that you would have the ability to usethis
in the wrapped functions and have it point to the Poet instance. I'm aware you are making sure that the poet instance is always the first argument in the wrapped functions (so this would be redundant) but would it hurt any? Wouldn't havingthis
point toGLOBAL
be risky?I am more trying to understand why than anything else.
The text was updated successfully, but these errors were encountered: