module.exports 里面如何递归

其实是我不知道如何引用那个functions obj 里的对应 fucntion

cookie = require './cookie'
module.exports =
  getUserInfo:->
    $.ajax
      url: '/get_user_info'
      type: 'GET'
      success: (data, status, response) =>
        if data.error != '0'
          console.log data.error
          #throw new Error(data.error)
        else
          localStorage.user_info = JSON.stringify(data.user_info)
          @user_info=data.user_info
      error:(data, status, response)->
        console.log data
        console.log status
        console.log response
  checkNewUserInfo:->
    if cookie.getCookieValue('user_id') == localStorage.cookie_user_id and localStorage.user_info
      JSON.parse(localStorage.user_info)
      @user_info=JSON.parse(localStorage.user_info)
    else
      @getUserInfo()
      localStorage.cookie_user_id = cookie.getCookieValue('user_id')

我想在 checkNewUserInfo 里调用它邻居的 getUserInfo 函数,发现不行

其实改成这样就可以了

cookie = require './cookie'
user_info =
  getUserInfo:->
    $.ajax
      url: '/get_user_info'
      type: 'GET'
      success: (data, status, response) =>
        if data.error != '0'
          console.log data.error
          #throw new Error(data.error)
        else
          localStorage.user_info = JSON.stringify(data.user_info)
          @user_info=data.user_info
      error:(data, status, response)->
        console.log data
        console.log status
        console.log response
  checkNewUserInfo:->
    if cookie.getCookieValue('user_id') == localStorage.cookie_user_id and localStorage.user_info
      JSON.parse(localStorage.user_info)
      @user_info=JSON.parse(localStorage.user_info)
    else
      user_info.getUserInfo()
      localStorage.cookie_user_id = cookie.getCookieValue('user_id')

module.exports = user_info

搞个 user_info 变量存起来,怎么用都可以了