<!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. vc6.0 点编译时提示Cannot complile the file &#39;D:\souce-code\vc-workspace\对话框\MainFrm.h&#39;; no compile tool is

    问题描写叙述: vc6.0程序,点击编译时提示对话框,内容为: Cannot complile the file 'D:\souce-code\vc-workspace\对话框\MainFrm.h'; ...

  2. Android Java使用JavaMail API发送和接收邮件的代码示例

    JavaMail是Oracle甲骨文开发的Java邮件类API,支持多种邮件协议,这里我们就来看一下Java使用JavaMail API发送和接收邮件的代码示例 使用Javamail发送邮件,必需的j ...

  3. 组件绑定v-model,实现最大化复用

    看优秀的vue项目,对组件的封装做的都非常到位,比如一个按钮都可以实现复用,仔细研究会发现实现基础就是组件直接绑定v-model,来看看按钮: 比如有个点赞按钮,长这样: 当点赞之后变成这样: 相信很 ...

  4. 【POJ 3415】Common Substrings

    [链接]h在这里写链接 [题意]     求两个串的长度大于等于k的公共子串个数.     相同的重复计数. [题解]     先把两个字符串用一个分隔符分开.最好比出现的字符都大的一个数字.    ...

  5. [Immutable.js] Updating nested values with ImmutableJS

    The key to being productive with Immutable JS is understanding how to update values that are nested. ...

  6. 在Eclipse中运行Nutch2.3 分类: H3_NUTCH 2015-01-28 16:41 3175人阅读 评论(13) 收藏

    参考http://wiki.apache.org/nutch/RunNutchInEclipse 一.环境准备 1.下载nutch2.3源代码 wget http://mirror.bit.edu.c ...

  7. term- xshell VS securecrt

    Xshell使用技巧总结 https://www.cnblogs.com/zhangwuji/p/7155575.html SecureCRT与Xshell简单对比 http://ju.outofme ...

  8. XHTML 结构化:使用 XHTML 重构网站 分类: C1_HTML/JS/JQUERY 2014-07-31 15:58 249人阅读 评论(0) 收藏

    http://www.w3school.com.cn/xhtml/xhtml_structural_01.asp 我们曾经为本节撰写的标题是:"XHTML : 简单的规则,容易的方针.&qu ...

  9. IdentityServer4实战 - JWT Token Issuer 详解

    原文:IdentityServer4实战 - JWT Token Issuer 详解 一.前言 本文为系列补坑之作,拖了许久决定先把坑填完. 下文演示所用代码采用的 IdentityServer4 版 ...

  10. VS(Visual Studio)自动创建的文件格式

    .sln:solution,解决方案文件: .vsxproj:解决方案下的项目文件: .vssettings:环境设置文件, 菜单栏 ⇒ [工具]⇒ [导入和导出设置]⇒ 进行环境设置的导入和导出操作 ...