Pass the values, without sending as parameters in the function

Asked By: Anonymous

How can I pass the values userId, sessionId, cb, without sending as a parameter in the function?

userSessionInfo: function (userId, sessionId, cb) {
  if (!sessionId || sessionId == '') {
    let user_id = userId;

I need to do something like:

userSessionInfo: function () {
  userId = "..."; 
  sessionId = "..."; 
  cb = "...";

Is possible?


Solution

Answered By: Anonymous

If you want to call a function without passing any parameters, you could wrap that function in a class and treat it like a method.

_x000D_

_x000D_

class UserSession {
  constructor(userId) {
    this.userId = userId;
    this.sessionId = null;
    this.cb = null;
  }
  info() {
    if (!this.sessionId || this.sessionId == '') {
      let user_id = this.userId;
      return user_id;
    }
    return null;
  }
}

const userSession = new UserSession(1001);

console.log(userSession.info()); // 1001

_x000D_

_x000D_

x000D

techinplanet staff

techinplanet staff


Windows 10 Kaufen Windows 10 Pro Office 2019 Kaufen Office 365 Lizenz Windows 10 Home Lizenz Office 2019 Home Business Kaufen windows office 365 satın al follower kaufen instagram follower kaufen porno