<!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中对象的构建的更多相关文章

  1. jQuery中异步操作对象Deferred

    以下介绍一下jQuery中Deferred对象的使用: 1. 通过$.Deferred生成一个deferredObj对象; 2. deferredObj.done()指定操作成功时的回调函数; 3. ...

  2. JavaScript 中的window.event代表的是事件的状态,jquery事件对象属性,jquery中如何使用event.target

    http://wenda.haosou.com/q/1373868839069215 http://kylines.iteye.com/blog/1660236 http://www.cnblogs. ...

  3. jquery中获取当前点击对象

    jquery中获取当前点击对象的简单方法就是,在点击事件click中传入event对象 click(function(event)); 调用当前对象就是$(event.target);

  4. jquery中onclick="fn"中$(this)所代表的对象

    jquery中onclick="fn"中$(this)所代表的对象 js方法 function qiehuan(){ var src = $(this).attr("da ...

  5. javascript 学习笔记之JQuery中的Deferred对象

    Deffered是Jquery中的一个非常重要的对象,从1.5版本之后,Jquery中的ajax操作都基于Deffered进行了重构,这个对象的处理模式就像其他Javascript框中的Promise ...

  6. jQuery中$.extend(true,object1, object2);深拷贝对象

    语法:jQuery.extend( [deep ], target, object1 [, objectN ] ) 深浅拷贝对应的参数就是[deep],是可选的,为true或false.默认情况是fa ...

  7. JS的内置对象以及JQuery中的部分内容

     [js中的数组]              1  数组的概念:可以再内存中连续存储的多个有序元素的结构                元素的顺序:称为下标,通过下标查找对应元素.           ...

  8. JS自定义对象,正则表达式,JQuery中的一些知识点

    一:自定义对象 1.基本概念:①对象:包含一系列无序属性和方法的集合.②键值对:对象中的数据是以键值对的形式存在的,以键取值.③属性:描述对象特征的一系列变量.[对象中的变量]④方法:描述对象行为的一 ...

  9. JQuery中的回调对象

    JQuery中的回调对象 回调对象(Callbacks object)模块是JQuery中的一个很基础的模块,很多其他的模块(比如Deferred.Ajax等)都依赖于Callbacks模块的实现.本 ...

随机推荐

  1. 【例题5-6 UVA 540 】Team Queue

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 用两个队列模拟就好. 记录某个队在不在队列里面. 模拟 [错的次数] 在这里输入错的次数 [反思] 在这里输入反思 [代码] #in ...

  2. 取消UITableViewCell的背景色

    //无色 cell.selectionStyle = UITableViewCellSelectionStyleNone; //蓝色,也就是系统默认的颜色 cell.selectionStyle = ...

  3. 【LeetCode】【C++】Linked list cycle 2

    Given a linked list, return the node where the cycle begins. If there is no cycle, return null. Foll ...

  4. h5 video 点击自动全屏

    加上如下属性 https://blog.csdn.net/weixin_40974504/article/details/79639478 可阻止自动全屏播放,感谢 https://blog.csdn ...

  5. ldap chinese guide

    OpenLDAP2.4管理员指南 http://wiki.jabbercn.org/index.php/OpenLDAP2.4%E7%AE%A1%E7%90%86%E5%91%98%E6%8C%87% ...

  6. 解决Eclipse中的卡死现象

    解决Eclipse中的卡死现象 取消验证 windows–>perferences–>validation 把 除了manual 下面的全部点掉,build下只留 classpath de ...

  7. [D3] Convert Input Data to Output Values with Linear Scales in D3

    Mapping abstract values to visual representations is what data visualization is all about, and that’ ...

  8. event.relatedTarget、event.fromElement、event.toElement

    在标准DOM中,mouseover和mouseout所发生的元素可以通过event.target来访问,相关元素通过event.relatedTarget属性来访问.event.relatedTarg ...

  9. 独立博客网站FansUnion.cn运营2年的经验和教训以及未来规划

    今天,我把运营了2年的独立博客网站FansUnion给"归零"了.    2012年6月,我成功搭建了自己的博客网站FansUnion.cn,这是由于自己的不懈努力和时代发展成就的 ...

  10. Android JobService的使用及源码分析

    Google在Android 5.0中引入JobScheduler来执行一些需要满足特定条件但不紧急的后台任务,APP利用JobScheduler来执行这些特殊的后台任务时来减少电量的消耗.本文首先介 ...