Home » Javascript » Can I print something with console.log() in Promise? (DEBUGGING)

Can I print something with console.log() in Promise? (DEBUGGING)

Posted by: admin June 30, 2018 Leave a comment

Questions:

I’m trying to understand someone else’s code and here is the original code

// Using Mobx over Redux here. I don't think it's relevant to this problem. 
@action.bound init() { 
    this.time_interval = setInterval(actions.initTime, 1000);

// other file    
export const initTime = () => ({
    server_time: window.time || moment.utc(),
});

And I’m trying to console.log but it gives me an error.

@action.bound init() {
    // I guess it's checking if the current time is same with server's time.
    this.time_interval = setInterval(actions.initTime, 1000);
    console.log(actions.initTime); <- gives me function. 
    console.log(actions.initTime.server_time); <- undefined

// other file    
export const initTime = () => ({ <- This is returning Promise.? I usually used Redux-Thunk to handle all actions and I almost forgot how Promise worked. 
    console.log(window.time); <- syntax error
    server_time: window.time || moment.utc(),
});

So how do we print window.time and moment.utc()? Thanks!

UPDATE

export const initTime = () => ({
    server_time: window.time || moment.utc(),
}).then(console.log()); 
^- console.log(window.time) prints undefined
^- console.log(moment.utc()) prints undefined
^- console.log( window_time || moment.utc()) prints a function with few parameters such as 'is_UTC', 'isValid', '_locale'.

Data:

Answers: