Skip to content

Instantly share code, notes, and snippets.

@joecliff
Last active August 29, 2015 13:58
Show Gist options
  • Save joecliff/9927180 to your computer and use it in GitHub Desktop.
Save joecliff/9927180 to your computer and use it in GitHub Desktop.
使用q.js调用不支持promise的方法时的作用域问题
//最好总是使用带this绑定的q方法(相对保险)
Q.ninvoke(object, methodName, ...args); //直接执行
Q.nbind(nodeMethod, thisArg, ...args); //返回绑定参数后的方法
//不带直接绑定this作用域的,如果方法内用到了this,可能需要手动绑定
Q.nfcall(obj.method.bind(obj), ...args)
Q.nfapply(obj.method.bind(obj), args)
//其他类似 ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment