jQuery.proxy()代理、回调方法
来源:互联网 发布:单片机使用教程 编辑:程序博客网 时间:2024/06/03 06:42
jQuery.proxy( function, context )
jQuery.proxy( context, name )
var obj = { name: "John", test: function() { alert( this.name ); $("#test").unbind("click", obj.test); }}; $("#test").click( jQuery.proxy( obj, "test" ) ); // 以下代码跟上面那句是等价的:// $("#test").click( jQuery.proxy( obj.test, obj ) );// 可以与单独执行下面这句做个比较。// $("#test").click( obj.test );再看一下jquery.proxy的源码:
/* jQuery 源码之 proxy: 使用 apply 形式, 执行回调函数.*/jQuery.proxy = function( fn, proxy, thisObject ) { if ( arguments.length === 2 ) { // jQuery.proxy(context, name); if ( typeof proxy === "string" ) { thisObject = fn; fn = thisObject[ proxy ]; proxy = undefined; /* 转化结果: thisObject -> context fn -> name proxy -> undefined */ } // jQuery.proxy(name, context); else if ( proxy && !jQuery.isFunction( proxy ) ) { thisObject = proxy; proxy = undefined; } } if ( !proxy && fn ) { /* 使用 proxy 保证 函数执行时, context 为指定值 */ proxy = function() { return fn.apply( thisObject || this, arguments ); }; } // Set the guid of unique handler to the same of original handler, so it can be removed if ( fn ) { proxy.guid = fn.guid = fn.guid || proxy.guid || jQuery.guid++; } // So proxy can be declared as an argument return proxy;}
其实就是平常使用的的call和apply,大部分的时候作为回调使用。
- jQuery.proxy()代理、回调方法
- jQuery.proxy()代理、回调方法
- jQuery $.proxy() 方法
- Ruby gem的proxy代理设置方法
- ES6 -- 最佳代理Proxy:实例方法
- 代理(Proxy)
- Proxy 代理
- Proxy 代理
- Proxy代理
- 代理proxy
- 代理(Proxy)
- 代理Proxy
- jquery事件代理方法
- jQuery $.proxy
- jQuery $.proxy()
- 校园网防PROXY代理原理与方法分析
- ssh proxy 代理上网的设置方法[图文]
- 通过代理抓取网页code方法 proxy httpurlconnection
- HDU 4081 Qin Shi Huang's National Road System 最小生成树变形
- 2013年9月28号
- [C语言]菜鸟的一些理解-指针
- PHP中使用cookie和session
- Mybatis3.2.3 知识点快速摘要
- jQuery.proxy()代理、回调方法
- 软件销售行业软件公司销售参考操作手册-之6-软件销售步骤拆分
- 使用LauchPopupListener过滤LOV数据
- Linux常用命令大全
- build-essential的作用
- 相似图片搜索的原理
- Vmware + ubuntu 12.04 LTS虚拟机下提供DHCP服务
- java 转义字符
- 如何比较DateTime类型数据的大小