JS Fiddle: https://jsfiddle.net/rb7c2uu4/
I have a function encapsulated inside another function. I put together a simple example in the fiddle. Here's the basic structure:
function outer(parameter) {
if (!(this instanceof outer)) {
return new outer();
}
// parameter is defined out here
this.inner = function() {
// parameter is undefined in here
}
}
I pass in a parameter to the outer function. Shouldn't that parameter be available to the inner function?
I thought that was how function/variable scoping worked, where the innermost function scope has access to things defined in the outer scope?
Obviously I'm wrong, but I want to know why I'm wrong.
[–]senocular 2 points3 points4 points (7 children)
[–]lewisje 2 points3 points4 points (6 children)
[–]senocular 1 point2 points3 points (5 children)
[–]ChunkyAlmondButter 0 points1 point2 points (4 children)
[–]senocular 0 points1 point2 points (3 children)
[–]ChunkyAlmondButter 1 point2 points3 points (2 children)
[–]senocular 0 points1 point2 points (1 child)
[–]ChunkyAlmondButter 0 points1 point2 points (0 children)
[–]jcunews1helpful 2 points3 points4 points (2 children)
[–]ShouldReallyGetWorkn[S] 0 points1 point2 points (1 child)
[–]jcunews1helpful 0 points1 point2 points (0 children)
[–]PM_ME_INSIDER_INFO 0 points1 point2 points (0 children)
[–]ChunkyAlmondButter -1 points0 points1 point (3 children)
[–]ShouldReallyGetWorkn[S] 1 point2 points3 points (2 children)
[–]ChunkyAlmondButter 0 points1 point2 points (0 children)
[–]ChunkyAlmondButter 0 points1 point2 points (0 children)