Reputation: 47
function caller(id){
accessParam()
}
function accessParam() {
// access caller param without passing
if(id){
// do something
}
}
// execute caller function
caller(1001)
Is there a posible way to access without passing paramter accessParam()
Upvotes: 1
Views: 284
Reputation: 780984
Is there a posible way to access without passing paramter
accessParam()
No, there isn't. id
is a local variable within caller()
, and there's no way to access local variables from outside the function.
And even if there were, it would be very poor design, since it would mean that accParam()
could only be used from that function. The general idea of functions is that they should operate independently.
Passing parameters and returning values is the cornerstone of abstraction in programming.
Upvotes: 2