does jquery have an equivalent of dojo.hitch()?

前端 未结 7 1851
甜味超标
甜味超标 2021-02-07 07:24

Forgive my ignorance as I am not as familiar with jquery. Is there an equivalent to dojo.hitch()? It returns a function that is guaranteed to be executed in the given scope.

7条回答
  •  没有蜡笔的小新
    2021-02-07 08:04

    I know this has been answered, but not correctly. jQuery.proxy is what you are looking for I believe.

    UPDATE

    Many, many years later after lots of JavaScript work, and after stripping out my usage of jQuery since browser compatibility has become less of an issue, I would recommend using Function.prototype.bind over jQuery.proxy, as @bobince suggested. While this is still the correct answer to the original question, I feel obligated to direct people to a vanilla solution rather than relying on jQuery.

提交回复
热议问题