Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
107 views
in Technique[技术] by (71.8m points)

javascript - how can I send a value from one function to the other

I have a function that checks whether the user is logged in or not and another that protects the routes and I wanted the function's true or false value to check whether the user is logged in or not to be sent to "const authentication" in any way to do it? I thank anyone who can help

 firebase.auth().onAuthStateChanged((user) => { 
    
      if (user) {
           this.login = true /// types this     //// this value
          console.log('logged')
       
        } else {
        this.login = false               /// or this values
          console.log('nologin');
        }
        
    });

const authentication={
  isLoggedIn: this.login,   //// go here
  onAuthentication(){
    this.isLoggedIn=true;
  },
  getLogInStatus(){
    return this.isLoggedIn;
  }
}
question from:https://stackoverflow.com/questions/66067699/how-can-i-send-a-value-from-one-function-to-the-other

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
var globalVariable;
function function1()
{
  //set a value
  globalVariable=12;
  function2();
}

function function2()
{
  //local gets that same value
  var local = globalVariable;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...