jQuery中对象的构建
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>jQuery</title>
<script src="jquery.js"></script>
</head>
<body>
<div id="aaron">jQuery</div> <script type="text/javascript"> (function(window, factory){
factory(window);
}(typeof window !== undefined ? window : this, function(window, noGlobal){
var $jQuery = function(selector, context){
return new $jQuery.fn.init( selector, context );
}
$jQuery.fn = $jQuery.prototype = {
init: function(){
this.name = "aa";
return this;
},
constructor: $jQuery
}
if(typeof noGlobal === "undefined"){
window.$jQuery = $jQuery;
}
return $jQuery;
}))
var a = $jQuery();
show(a.name);
function show(data) {
jQuery("body").append('<li>' + data + '</li>')
} </script>
</body>
</html>
分离构造器
http://www.imooc.com/code/3398
var $$ = ajQuery = function(selector) {
this.selector = selector;
return this
}
ajQuery.fn = ajQuery.prototype = {
selectorName:function(){
return this.selector;
},
constructor: ajQuery
}
var a = new $$('aaa'); //实例化
console.log(a);
var name = a.selectorName();//aaa //得到选择器名字
console.log(name);
改进,去掉new
ar $$ = ajQuery = function(selector) {
console.log(this);
if(!(this instanceof ajQuery)){
return new ajQuery(selector);
}
this.selector = selector;
return this;
}
ajQuery.fn = ajQuery.prototype = {
selectorName:function(){
return this.selector;
},
constructor: ajQuery
}
var a = $$('aaa'); //实例化
console.log(a);
var name = a.selectorName();//aaa //得到选择器名字
console.log(name);
jQuery中对象的构建的更多相关文章
- jQuery中异步操作对象Deferred
以下介绍一下jQuery中Deferred对象的使用: 1. 通过$.Deferred生成一个deferredObj对象; 2. deferredObj.done()指定操作成功时的回调函数; 3. ...
- JavaScript 中的window.event代表的是事件的状态,jquery事件对象属性,jquery中如何使用event.target
http://wenda.haosou.com/q/1373868839069215 http://kylines.iteye.com/blog/1660236 http://www.cnblogs. ...
- jquery中获取当前点击对象
jquery中获取当前点击对象的简单方法就是,在点击事件click中传入event对象 click(function(event)); 调用当前对象就是$(event.target);
- jquery中onclick="fn"中$(this)所代表的对象
jquery中onclick="fn"中$(this)所代表的对象 js方法 function qiehuan(){ var src = $(this).attr("da ...
- javascript 学习笔记之JQuery中的Deferred对象
Deffered是Jquery中的一个非常重要的对象,从1.5版本之后,Jquery中的ajax操作都基于Deffered进行了重构,这个对象的处理模式就像其他Javascript框中的Promise ...
- jQuery中$.extend(true,object1, object2);深拷贝对象
语法:jQuery.extend( [deep ], target, object1 [, objectN ] ) 深浅拷贝对应的参数就是[deep],是可选的,为true或false.默认情况是fa ...
- JS的内置对象以及JQuery中的部分内容
[js中的数组] 1 数组的概念:可以再内存中连续存储的多个有序元素的结构 元素的顺序:称为下标,通过下标查找对应元素. ...
- JS自定义对象,正则表达式,JQuery中的一些知识点
一:自定义对象 1.基本概念:①对象:包含一系列无序属性和方法的集合.②键值对:对象中的数据是以键值对的形式存在的,以键取值.③属性:描述对象特征的一系列变量.[对象中的变量]④方法:描述对象行为的一 ...
- JQuery中的回调对象
JQuery中的回调对象 回调对象(Callbacks object)模块是JQuery中的一个很基础的模块,很多其他的模块(比如Deferred.Ajax等)都依赖于Callbacks模块的实现.本 ...
随机推荐
- Unity(IOC)学习笔记
原文:Unity(IOC)学习笔记 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/m0_37591671/article/details/79432 ...
- 键盘钩子监测按键后,获取键码及按键名称(MFC)
LRESULT CALLBACK LowLevelKeyboardProc(int nCode,WPARAM wParam,LPARAM lParam){ if(nCode ==HC_ACTION & ...
- C++中的虚析构函数、纯虚析构函数具体解释
C++中析构函数能够为纯虚函数吗? 众所周知.在实现多态的过程中,一般将基类的析构函数设为virtual.以便在delete的时候能够多态的链式调用.那么析构函数能否够设为纯虚呢? class CBa ...
- css3-11 如何让html中的不规则单词折行
css3-11 如何让html中的不规则单词折行 一.总结 一句话总结:用word-wrap属性:word-wrap:break-word; 1.word-break和word-wrap的区别? 推荐 ...
- URL validation failed. The error could have been caused through the use of the browser's navigation
URL validation failed. The error could have been caused through the use of the browser's navigation ...
- Java获取文件路径的几种方法
第一种: File f = new File(this.getClass().getResource("/").getPath()); System.out.println(f); ...
- $.ajax 请求 拦截器 重定向 无效 解决办法
在ajax 异步请求下 拦截器过滤器中使用 重定向 页面响应无效 我这里用的是springboot框架,用拦截器实现 对请求的拦截 ,session超时直接跳转到login.html页面. 后台代码: ...
- DOM中Event 对象如何使用
DOM中Event 对象如何使用 一.总结 一句话总结: 1.将event作为参数传递进来,然后就可以调用event对象的各种属性和方法了. <body onmousedown="wh ...
- python 使用顺序表实现栈和队列
栈: # -*- coding: utf-8 -*- # @author: Tele # @Time : 2019/04/24 下午 2:33 # 采用list(顺序表)实现栈结构,后入先出 clas ...
- System.nanoTime()和System.currentTimeMillis()性能问题
之前给模块做性能优化的时候,需要将性能调到毫秒级,使用了System.nanoTime()和System.currentTimeMillis()对代码分片计时分析耗时操作,后发现在串行情况下性能达 ...