bearcat this被覆盖

@fantasyni
bearcat的bean之间函数使用的时候,发现有时bean.prototype.xxx函数的this没有指向bean自己,而是被覆盖成了视乎是顶层的一个什么this,打印如下。这是什么情况?我没用用任何magic $, 所有对象都是json手动配置的bean,signleton

[2015-05-21 15:20:30.287] [INFO] app - [bean][handler][rpc_server] registerClient this = { ArrayBuffer: [Function: ArrayBuffer],
  Int8Array: { [Function: Int8Array] BYTES_PER_ELEMENT: 1 },
  Uint8Array: { [Function: Uint8Array] BYTES_PER_ELEMENT: 1 },
  Uint8ClampedArray: { [Function: Uint8ClampedArray] BYTES_PER_ELEMENT: 1 },
  Int16Array: { [Function: Int16Array] BYTES_PER_ELEMENT: 2 },
  Uint16Array: { [Function: Uint16Array] BYTES_PER_ELEMENT: 2 },
  Int32Array: { [Function: Int32Array] BYTES_PER_ELEMENT: 4 },
  Uint32Array: { [Function: Uint32Array] BYTES_PER_ELEMENT: 4 },
  Float32Array: { [Function: Float32Array] BYTES_PER_ELEMENT: 4 },
  Float64Array: { [Function: Float64Array] BYTES_PER_ELEMENT: 8 },
  DataView: [Function: DataView],
  global: [Circular],
  process: 
   { title: 'node',
     version: 'v0.10.38',
     moduleLoadList: 
      [ 'Binding evals',
        'Binding natives',
        'NativeModule events',
        'NativeModule buffer',
        'Binding buffer',
        'NativeModule assert',
        'NativeModule util',
        'NativeModule path',
        'NativeModule module',
        'NativeModule fs',
        'Binding fs',
        'Binding constants',
        'NativeModule stream',
        'NativeModule _stream_readable',
        'NativeModule _stream_writable',
        'NativeModule _stream_duplex',
        'NativeModule _stream_transform',
        'NativeModule _stream_passthrough',
        'NativeModule os',
        'Binding os',
        'NativeModule console',
        'Binding tty_wrap',
        'NativeModule tty',
        'NativeModule net',
        'NativeModule timers',
        'Binding timer_wrap',
        'NativeModule _linklist',
        'Binding cares_wrap',
        'Binding signal_wrap',
        'NativeModule crypto',
        'Binding crypto',
        'NativeModule string_decoder',
        'NativeModule tls',
        'NativeModule url',
        'NativeModule punycode',
        'NativeModule querystring',
        'NativeModule constants',
        'NativeModule http',
        'NativeModule freelist',
        'Binding http_parser',
        'NativeModule https',
        'NativeModule zlib',
        'Binding zlib',
        'NativeModule dgram',
        'Binding udp_wrap',
        'NativeModule dns',
        'NativeModule child_process',
        'Binding process_wrap',
        'Binding tcp_wrap',
        'NativeModule cluster' ],
     versions: 
      { http_parser: '1.0',
        node: '0.10.38',
        v8: '3.14.5.9',
        ares: '1.9.0-DEV',
        uv: '0.10.36',
        zlib: '1.2.8',
        modules: '11',
        openssl: '1.0.1m' },
     arch: 'x64',
     platform: 'linux',
     argv: 
      [ 'node',
        '/home/roy/project/rrpc2/server/app.js',
        '-e',
        'dev',
        '-st',
        'main_admin' ],
     execArgv: [],
     env: 
      { XDG_SESSION_ID: '14',
        TERM: 'xterm',
        SHELL: '/bin/bash',
        SSH_CLIENT: '192.168.1.109 8196 22',
        SSH_TTY: '/dev/pts/1',
        USER: 'root',
        LS_COLORS: 'rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.axa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36:',
        MAIL: '/var/mail/root',
        PATH: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games',
        PWD: '/home/roy/project/rrpc2/server',
        LANG: 'en_HK.UTF-8',
        SHLVL: '1',
        HOME: '/root',
        LANGUAGE: 'en_HK:en',
        LOGNAME: 'root',
        SSH_CONNECTION: '192.168.1.109 8196 192.168.1.66 22',
        LESSOPEN: '| /usr/bin/lesspipe %s',
        XDG_RUNTIME_DIR: '/run/user/0',
        LESSCLOSE: '/usr/bin/lesspipe %s %s',
        _: '/usr/local/bin/node',
        OLDPWD: '/root',
        BEARCAT_LOGGER: 'off',
        BEARCAT_ANNOTATION: 'off' },
     pid: 29483,
     features: 
      { debug: false,
        uv: true,
        ipv6: true,
        tls_npn: true,
        tls_sni: true,
        tls: true },
     _needImmediateCallback: true,
     execPath: '/usr/local/bin/node',
     debugPort: 5858,
     _getActiveRequests: [Function],
     _getActiveHandles: [Function],
     _needTickCallback: [Function],
     reallyExit: [Function],
     abort: [Function],
     chdir: [Function],
     cwd: [Function],
     umask: [Function],
     getuid: [Function],
     setuid: [Function],
     setgid: [Function],
     getgid: [Function],
     getgroups: [Function],
     setgroups: [Function],
     initgroups: [Function],
     _kill: [Function],
     _debugProcess: [Function],
     _debugPause: [Function],
     _debugEnd: [Function],
     hrtime: [Function],
     dlopen: [Function],
     uptime: [Function],
     memoryUsage: [Function],
     binding: [Function],
     _usingDomains: [Function],
     _tickInfoBox: { '0': 18, '1': 3, '2': 1 },
     _events: 
      { SIGWINCH: [Function],
        exit: [Function],
        SIGINT: [Function],
        SIGTERM: [Function],
        SIGHUP: [Function] },
     _emittingTopLevelDomainError: false,
     domain: null,
     _maxListeners: 10,
     EventEmitter: { [Function: EventEmitter] listenerCount: [Function] },
     _fatalException: [Function],
     _exiting: false,
     assert: [Function],
     config: { target_defaults: [Object], variables: [Object] },
     nextTick: [Function: nextTick],
     _currentTickHandler: [Function: _nextTick],
     _nextDomainTick: [Function: _nextDomainTick],
     _tickCallback: [Function: _tickCallback],
     _tickDomainCallback: [Function: _tickDomainCallback],
     _tickFromSpinner: [Function: _tickFromSpinner],
     maxTickDepth: 1000,
     stdout: [Getter],
     stderr: [Getter],
     stdin: [Getter],
     openStdin: [Function],
     exit: [Function],
     kill: [Function],
     addListener: [Function],
     on: [Function],
     removeListener: [Function],
     mainModule: 
      { id: '.',
        exports: {},
        parent: null,
        filename: '/home/roy/project/rrpc2/server/app.js',
        loaded: true,
        children: [Object],
        paths: [Object] },
     _immediateCallback: [Function: processImmediate] },
  GLOBAL: [Circular],
  root: [Circular],
  Buffer: 
   { [Function: Buffer]
     isEncoding: [Function],
     poolSize: 8192,
     isBuffer: [Function: isBuffer],
     byteLength: [Function],
     concat: [Function],
     _charsWritten: 7707 },
  setTimeout: [Function],
  setInterval: [Function],
  clearTimeout: [Function],
  clearInterval: [Function],
  setImmediate: [Function],
  clearImmediate: [Function],
  console: [Getter],
  interface: 'validate' }
标签: bug 反馈 bearcat
roytan 在 2015-5-21 18:36发布 分享到 weibo
2 回复
#1 roytan 2015-5-21 18:42 回复

这bug出现以后,我的bean内部函数间调用我只能用

bearcat.getBean('handler:rpc_server').checkClientsAlive()

来替换

this.checkClientsAlive()

这样就可以正常运行了

#2 {3} fantasyni 2015-5-21 19:07 回复

方便的话,提供给修改后的可以复现的例子吧

roytan 2015-5-21 19:36 回复

写了很多代码了,突然出现的。不好分享代码。。。
getBean返回的是对象吧。bearcat.getBean('yyy').xxx()的时候,xxx函数内部this有可能被覆盖吗?我是在xxx函数第一行就打印的。

roytan 2015-5-21 20:00 回复

应该是我外面调用的问题,我先把func引用出来封装了一下,应该用apply把bean设置回去的。
sorry,我的错

fantasyni 2015-5-21 20:18 回复

@roytan 哈哈哈 问题解决了就好

回到顶部