Fork me on GitHub
代码改变世界

jQuery.proxy()函数

2015-08-12 23:46  autrol  阅读(222)  评论(0)    收藏  举报
jQuery.proxy(),接受一个函数,然后返回一个新函数,并且这个新函数始终保持了特定的上下文(context)语境。
 
context 代表上下文
name是上下文的某个属性
jQuery.proxy (context.name, context)
jQuery.proxy (context, "name")
上面两条语句的功能是一样一样的
 
举例:
$.post(url, {}, $.proxy(this.function, this));//function指代函数名
$.post(url, {}, $.proxy(this, "function"));
上面两条语句的功能是一样一样的