Last active
October 6, 2015 15:28
-
-
Save aepyornis/1d086dc4c0282a8c35e1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function doSomething() { | |
var someValue = "this is an important value"; | |
anotherFuctionDefinedElsewhere(); | |
} | |
function anotherFuctionDefinedElsewhere () { | |
// this function can't access someValue | |
console.log(someValue); | |
} | |
/// typically this can be easily solved by passing someValue into the function: | |
function doSomething() { | |
var someValue = "this is an important value"; | |
anotherFuctionDefinedElsewhere(someValue); | |
} | |
function anotherFuctionDefinedElsewhere (someValue) { | |
// now this function can access someValue | |
console.log(someValue); | |
} | |
// Is there a way to have anotherFuctionDefinedElsewhere() access a local variable of doSomething() without passing? | |
another way to pass values between functions defined separately
function doSomething() {
this.someValue = "this is an important value";
anotherFuctionDefinedElsewhere.apply(this);
}
function anotherFuctionDefinedElsewhere () {
console.log(this.someValue);
}
doSomething();
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
if i understand correctly something like this might work: