Closure is not necessarily a function, it can be any data type.
Closure is just a reference that is in the accessible scope, whose value comes from a scope that is not accessible.
"Closure is not necessarily a function, it can be any data type" not, exactly. According to MDN: "A closure is the combination of a function bundled together (enclosed) with references to its surrounding state (the lexical environment)." (source: developer.mozilla.org/en-US/docs/W...)
It's wrong when you phrase it like "JUST a reference that" ("just" suggests it's only that, not "one aspect of") when it's clearly not "just a" :) That's what I meant ;)
Wrong. A closure is the combination of a function and some references to either values or variables, depending on the language.
It's commonly simplified to just a function that has access to it's calling scope, because it effectively behaves that way in javascript and pretty much any other language that has them.
Log in to continue
We're a place where coders share, stay up-to-date and grow their careers.
Closure is not necessarily a function, it can be any data type.
Closure is just a reference that is in the accessible scope, whose value comes from a scope that is not accessible.
"Closure is not necessarily a function, it can be any data type" not, exactly. According to MDN: "A closure is the combination of a function bundled together (enclosed) with references to its surrounding state (the lexical environment)." (source: developer.mozilla.org/en-US/docs/W...)
That is not wrong. That's just one aspect of closures.
It's wrong when you phrase it like "JUST a reference that" ("just" suggests it's only that, not "one aspect of") when it's clearly not "just a" :) That's what I meant ;)
Wrong. A closure is the combination of a function and some references to either values or variables, depending on the language.
It's commonly simplified to just a function that has access to it's calling scope, because it effectively behaves that way in javascript and pretty much any other language that has them.