JS问题笔记——模拟Jq底层实现工厂模式
2024-08-26 02:46:37
<script type="text/javascript"> (function (window,undefined){ function _$(arguments)
{ } _$.prototype={
constructor:_$,
addEvent:function(){ alert("addEvent");
return this;
},
getStyle:function(){
alert('getStyle');
return this;
}
}
window.$=_$; _$.onReady=function(fn){
window.$=function(){
return new _$(arguments);
} fn(); } })(window) $.onReady(function(){
$("inq").addEvent().getStyle();
}) </script> <script type="text/javascript"> (function (window,undefined){ function _$(arguments)
{ }
Function.prototype.method=function(methodName,fn)
{
this.prototype[methodName]=fn;
return this;
} _$.prototype={
constructor:_$,
addEvent:function(){ alert("addEvent");
return this;
},
getStyle:function(){
alert('getStyle');
return this;
}
}
window.$=_$; _$.onReady=function(fn){
window.$=function(){
return new _$(arguments);
} _$.method('addEvent',function(){
alert("addEvent2");
return this;
}).method('getStyle',function(){
alert("getStyle2");
return this;
});
fn();
} })(window) $.onReady(function(){
$("inq").addEvent().getStyle();
})
//为什么要加_$.method()? 不加也行?
</script>
最新文章
- mac上使用imagealpha命令对图片进行压缩批处理
- 安装Linux 16.04 时,选择好分区后,进到选择地点的界面后,总是闪退,退到最原始的界面
- Unbunt vi 编辑器键盘按键不正确的一次经历与解决方案
- NativeScript工作原理
- Sql Server建立链接服务器访问Access的MDB数据库
- linux内核系列(二)内核数据结构之链表
- 判断richtextbox选中的是否为图片
- RazorEngine 学习笔记
- tomcat 项目部署问题
- JavaSE基础篇—数据类型和运算符
- CentOS中对ext4文件系统做磁盘配额
- iOS XML解析使用-韩国庆
- 02Hadoop二次排序2
- maven配置文件setting.xml
- 前端-关于 Vue 和 React 区别的一些笔记
- Java并发编程之final域的内存语义
- 谈应用环境下的TIME_WAIT和CLOSE_WAIT[转]
- 查看Windows端口及端口关闭方法(转)
- Poi读取Excle报错 java.util.zip.ZipException: invalid stored block lengths
- sqlserver 文件与文件组的使用和优化
热门文章
- 配置RMAN备份环境
- perf学习-linux自带性能分析工具
- jmeter导入DB数据再再优化
- 【BZOJ1001】[BeiJing2006]狼抓兔子
- [刷题]算法竞赛入门经典(第2版) 6-6/UVa12166 - Equilibrium Mobile
- 全景智慧城市——NOW!!!VRSHOPPING颠覆你的购物认知!
- .NET面试题系列[18] - 多线程同步(1)
- swift学习 - tableView自适应高度1(xib autoLayout)
- java中为什么实体类需要实现序列化
- 探讨SQL Server并发处理队列数据不阻塞解决方案