从zepto中学习方法
前言,今天开始学习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中学习方法的更多相关文章
- zepto中的touch库与fastclick
1. touch库实现了什么和引入背景 click事件在移动端上会有 300ms 的延迟,同时因为需要 长按 , 双触击 等富交互,所以我们通常都会引入类似 zepto 这样的库.zepto 中tou ...
- 这些Zepto中实用的方法集
前言 时间过得可真快,转眼间2017年已去大半有余,你就说吓不吓人,这一年你成长了多少,是否荒度了很多时光,亦或者天天向上,收获满满.今天主要写一些看Zepto基础模块时,比较实用的部分内部方法,在我 ...
- zepto中的属性设置
上次看zepto的init方法时,有一段属性设置的代码,先来看看其表现: if (isPlainObject(properties)) { nodes = $(dom) $.each(properti ...
- zepto中$.proxy()的到底有多强大?
好吧,其实是标题党了,哈哈,只是想总结一下工作中遇到$.proxy()的用法而已. 一.语法: $.proxy()有两种使用语法 1)$.proxy(fn,context),fn是一个函数,conte ...
- 使用zepto中animate报错“Uncaught TypeError: this.bind is not a function”的解决办法
在使用zepto时,我先引入zepto.min.js,然后引入fx.js,但是在使用animate函数时,控制台却报如下错误: Uncaught TypeError: this.bind is not ...
- 阻止长按复制页面中的内容;zepto中touch中的应用必须先加载event模块之后;
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- zepto中的scrollTo
//zepto没有scrollTo动画,这里扩展了一个scrollTo函数 $.fn.scrollTo = function(options) { var defaults = { scrollTop ...
- zepto中给不存在的元素设置样式并绑定事件的坑
在移动端使用zepto选择器时,一般如果元素不存在会返回一个空的zepto对象. zepto在设置元素样式时,提供了两个入参方式,一种键值对方式$(".ter").css({&qu ...
- Zepto中的Swipe事件失效
需要阻止浏览器默认滑动的事件 document.addEventListener('touchmove', function (event) { event.preventDefault(); }, ...
随机推荐
- 我的android学习经历26
ViewPager的使用 ViewPager就想微信或者qq的顶部的导航栏一样,滑动可以改变到不同的View或者Fragment 使用方法: 在布局文件中定义标签: android.support.v ...
- C#窗体截屏,简单例子
private void button1_Click(object sender, EventArgs e) { Rectangle rect = System.Windows.Forms.Syste ...
- 【leetcode❤python】342. Power of Four
#-*- coding: UTF-8 -*- class Solution(object): def isPowerOfFour(self, num): ""& ...
- Linux 新手非常有用的命令
http://www.cnblogs.com/felix-/p/4341773.html Linux 新手非常有用的命令 你打算从Windows换到Linux上来,还是你刚好换到Linux上来?哎哟! ...
- CANopen笔记1
CAN现场总线只定义了OSI网络模型的第一层(物理层) 和第二层(数据链路层) ,而这两层一般已被CAN硬件完全实现了.由于没有规定应用层,本身并不完整,需要一个高层协议来定义CAN报文中的11/29 ...
- 列联表(Crosstabs)
四格表(2*2的列联表): Tmin为最小的频数:N为频数之和. 1 当 Tmin≥5,N≥40时, 用普通卡方检验公式;2 当1≦Tmin≦5, N≥40时, 用校正卡方检验公式;3 Tmin< ...
- Python使用requirements.txt安装类库
摘要:我们为何要应用requirements.txt呢? 首要应用目标: 任何 运用顺序 平常 须要设置装置 所需并 依附 一组类库去知足 事情请求 . 请求 文件 是 指定 战 一次性 装置 包 的 ...
- Qt修改xml文件
<taskpackage styleId="styles/2dc70235-e48b-4e11-b074-3c3f773ae1f3" id="3333" ...
- tesseract-ocr了解
安装文件下载地址 http://tesseract-ocr.googlecode.com/files/tesseract-ocr-setup-3.01-1.exe README For the lat ...
- mysql数据小姿势
CREATE TABLE `information` ( `NUMBER` bigint(20) NOT NULL AUTO_INCREMENT,//将number设为自增字段 `USER_NAM ...