博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
jQuery中对象的构建
阅读量:4595 次
发布时间:2019-06-09

本文共 968 字,大约阅读时间需要 3 分钟。

    
jQuery
jQuery

 

分离构造器

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);

 

转载于:https://www.cnblogs.com/darr/p/5104675.html

你可能感兴趣的文章
swoolefy PHP的异步、并行、高性能网络通信引擎内置了Http/WebSocket服务器端/客户端...
查看>>
Python学习笔记
查看>>
unshift()与shift()
查看>>
使用 NPOI 、aspose实现execl模板公式计算
查看>>
行为型模式:中介者模式
查看>>
How to Notify Command to evaluate in mvvmlight
查看>>
33. Search in Rotated Sorted Array
查看>>
461. Hamming Distance
查看>>
Python垃圾回收机制详解
查看>>
{面试题1: 赋值运算符函数}
查看>>
Node中没搞明白require和import,你会被坑的很惨
查看>>
Python 标识符
查看>>
Python mysql 创建连接
查看>>
企业化的性能测试简述---如何设计性能测试方案
查看>>
centos7 安装中文编码
查看>>
POJ - 3683 Priest John's Busiest Day
查看>>
正则表达式start(),end(),group()方法
查看>>
vuejs 学习旅程一
查看>>
javascript Date
查看>>
linux常用命令2
查看>>