前言,今天开始学习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. Linux有问必答:如何在Linux中修改环境变量PATH

    提问: 当我试着运行一个程序时,它提示“command not found”. 但这个程序就在/usr/local/bin下.我该如何添加/usr/local/bin到我的PATH变量下,这样我就可以 ...

  2. C++实现二叉树,运用模板,界面友好,操作方便 运行流畅

    //.h文件 #ifndef TREE_H #define TREE_H #include<iostream> #include<iomanip> using namespac ...

  3. 【转】Ajax中send方法参数的使用(get/post)

    Ajax中send方法参数的使用 一般情况下,使用Ajax提交的参数多是些简单的字符串,可以直接使用GET方法将要提交的参数写到open方法的url参数中,此时send方法的参数为null. 例如 : ...

  4. Python 字符编码 zz

    http://www.cnblogs.com/huxi/archive/2010/12/05/1897271.html 1. 字符编码简介 1.1. ASCII ASCII(American Stan ...

  5. sql server 查询分析器消息栏里去掉“(5 行受影响)”

    sql server 查询分析器消息栏里去掉"(5 行受影响)"     在你代码的开始部分加上这个命令: set nocount on   记住在代码结尾的地方再加上: set ...

  6. Music Player团队项目(一)

    团队成员及分工 团队: Blue 团队共有六人 姓名:     学号后四位:       贡献分: 张   宇(队长)  1152          1+1.8=2.8分 侯贺琦          1 ...

  7. sencha touch之store

    store相当于数据库的表,是模型实例的集合.(是不是可以看成结构体数组) 可以对模型实例进行新建.更新.读取.删除.排序和过滤等操作. 创建store 由于store是表,必须要有模型或者定义字段, ...

  8. Xcode error: conflicting types for 'XXXX'

    问题描述:在main方法中调用了一个写在main方法后面的方法,比如: void main(){ A(); } void A(){} Xcode编译后就报错:conflicting types for ...

  9. Jconsole 监控tomcat

    通过jconsole监控可以获取监控tomcat的相关的数据信息 如何通过代码来获取其中的线程和内存状况呢? 首先要配置好jconsole监控的相关配置,一搜基本就是那一个, 配置配不好的话接下来的工 ...

  10. tomcat 启用Gzip 压缩进行优化

    打开conf/server.xml文件可以看到: <!-- Define a non-SSL HTTP/1.1 Connector on port 8080 -->     <Con ...