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
Query regarding coding paradigm used in this library. #62
Comments
Correct me if I'm wrong but you are wondering why some closures are defined using Well, this is for optimisation purpose. Defining functions using |
@ooflorent First of all thanks for replying . Well You are correct . I am asking the same. I am still not getting any idea, why using Function constructor is expensive. I can read following lines on mdn
May be I am thinking other way. Could you please elaborate ? |
Sure! Let's consider the following functions; they are really simple hook factory implementations: const f = (...fns) => (...args) => {
for (const fn of fns) {
fn(...args)
}
}
const g = (a, b, c) => (x, y) => {
a(x, y)
b(x, y)
c(x, y)
} Both functions achieve the same thing but Keep in mind that |
Oh Now I understand, basically the code which is returned is dynamic. so depending on varying number of arguments and other parameters, new functions is being created and returned. In this way, the code length will be dynamic and saves the code length in most cases. Thanks, @ooflorent. Actually going through webpack code to learn and contribute. You can close the issue !! |
What does monomorphic mean? @ooflorent |
Here is a good explanation: What's up with monomorphism? |
Thanks! |
Why in the code string concatenation is used to create the function? I can see, this approach is being followed in almost every file. Why shouldn't it be written as a normal function? For example like this in HookCodeFactory .
switch(this.options.type) { case "sync": return new Function(this.args(), "\"use strict\";\n" + this.header() + this.content({ onError: err =>
throw ${err};\n, onResult: result =>
return ${result};\n, onDone: () => "", rethrowIfPossible: true }));
The text was updated successfully, but these errors were encountered: