前言,今天开始学习Zepto源码,这里仅仅几下里面能用到的方法。。陆续补充ing...

一,判断类型函数

   function type(obj) {
return obj == null ? String(obj) : Object.prototype.toString.call(obj) || "Object";
}

稍作改变:

 (function () {

     function type(value) {
var getType = Object.prototype.toString;
var typeTemp = getType.call(value);
switch (typeTemp) {
case '[object Array]':
return "Array";
break;
case '[object Date]':
return "Date";
break;
case '[object Boolean]':
return "Boolean";
break;
case '[object Number]':
return "Number";
break;
case '[object Function]':
return "Function";
break;
default:
return "unKnow";
}
} function isArray(value) {
return type(value) == "Array";
} function isDate(value) {
return type(value) == "Date";
} function isBoolean(value) {
return type(value) == "Boolean";
} function isNumber(value) {
return type(value) == "Number";
} function isFunction(value) {
return type(value) == "Function";
} })();

补充

用getPrototypeOf和isProtoypeOf判断类型

     var time = new Date();
var result = (Object.getPrototypeOf(time) === Date.prototype);
console.log(result);
result=Date.prototype.isPrototypeOf(time);
console.log(result)

补充2016-12-05 11:19:40

网上一方法,用于判断类型

Object.prototype.toString.call(arg).slice(8,-1)

直接获取类型。。

二,replace结合表达式去改变字符串

   var str = "123aAbc";

     function stringDividerBetweenUnderline(str) {
return str.replace(/(\d+)([a-z]|[A-Z]+)/g, "$1_$2")
} var ss = stringDividerBetweenUnderline(str);
console.log(ss);

三,获取css属性

 var con1=document.querySelector(".con1");
console.log(window.getComputedStyle(con1).getPropertyValue("color"));

注意这里获取到的颜色是reba(255,0,0)我设置的是red

从zepto中学习方法的更多相关文章

  1. zepto中的touch库与fastclick

    1. touch库实现了什么和引入背景 click事件在移动端上会有 300ms 的延迟,同时因为需要 长按 , 双触击 等富交互,所以我们通常都会引入类似 zepto 这样的库.zepto 中tou ...

  2. 这些Zepto中实用的方法集

    前言 时间过得可真快,转眼间2017年已去大半有余,你就说吓不吓人,这一年你成长了多少,是否荒度了很多时光,亦或者天天向上,收获满满.今天主要写一些看Zepto基础模块时,比较实用的部分内部方法,在我 ...

  3. zepto中的属性设置

    上次看zepto的init方法时,有一段属性设置的代码,先来看看其表现: if (isPlainObject(properties)) { nodes = $(dom) $.each(properti ...

  4. zepto中$.proxy()的到底有多强大?

    好吧,其实是标题党了,哈哈,只是想总结一下工作中遇到$.proxy()的用法而已. 一.语法: $.proxy()有两种使用语法 1)$.proxy(fn,context),fn是一个函数,conte ...

  5. 使用zepto中animate报错“Uncaught TypeError: this.bind is not a function”的解决办法

    在使用zepto时,我先引入zepto.min.js,然后引入fx.js,但是在使用animate函数时,控制台却报如下错误: Uncaught TypeError: this.bind is not ...

  6. 阻止长按复制页面中的内容;zepto中touch中的应用必须先加载event模块之后;

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. zepto中的scrollTo

    //zepto没有scrollTo动画,这里扩展了一个scrollTo函数 $.fn.scrollTo = function(options) { var defaults = { scrollTop ...

  8. zepto中给不存在的元素设置样式并绑定事件的坑

    在移动端使用zepto选择器时,一般如果元素不存在会返回一个空的zepto对象. zepto在设置元素样式时,提供了两个入参方式,一种键值对方式$(".ter").css({&qu ...

  9. Zepto中的Swipe事件失效

    需要阻止浏览器默认滑动的事件 document.addEventListener('touchmove', function (event) { event.preventDefault(); }, ...

随机推荐

  1. android source

    h1 { margin-bottom: 0.21cm } h1.western { font-family: "Liberation Sans", sans-serif; font ...

  2. 如何在安装32位Oracle客户端组件的情况下以64位模式运行

    C#使用System.Data.OracleClient连接Oracle数据库.之前在WinXP上正常运行的程序移植到Windows 2008 x64上之后就连不上数据库了,错误信息如下:启动data ...

  3. Linux运维命令之一

    释放内存:syncecho 3 > /proc/sys/vm/drop_caches Linux查看Dell服务器型号命令:dmidecode | grep "Product Name ...

  4. mysql更改已有数据表的字符集,保留原有数据内容

    mysql更改已有数据表的字符集,保留原有数据内容     原文网址:http://blog.csdn.net/learn_2/article/details/6460370 环境:在应用开始阶段没有 ...

  5. HTTP Status 404–/webDemo/hello

    现在用一排很小的字写出来,我真是个大傻逼

  6. SQL疑难杂症【2】解决SQL订阅过程中找不到已经创建的订阅

    之前有写过一篇博客,主要是图解SQL复制技术:图解SQL 2008数据库复制,当时的测试环境是在我本地同一个服务器上面,所以测试的时候可谓是一帆风顺,最近公司要做一个数据同步的事物,所以再次在不同的服 ...

  7. Ubuntu下手动安装VMware Tools步骤

    To mount the CD image and extract the contents: Power on the virtual machine. Log in to the virtual ...

  8. web工程中各类地址写法的总结

    首先打一个"/" //如果地址给服务器用,那么"/"就代表该web应用 , 如果给浏览器用的,那么"/"就代表网站(其下有多个web应用) ...

  9. 堆内存指针的管理类(禁,引数(指针copy),值copy,移)

    //copyp template<typename T> class pm_copyP{ public: pm_copyP(T* _p); pm_copyP(const pm_copyP& ...

  10. 常用sql(转)

    1增 1.1[插入单行]insert [into] <表名> (列名) values (列值)例:insert into Strdents (姓名,性别,出生日期) values ('开心 ...