zepto 学习笔记

1、复制

(1)浅层复制

$.extend(target, source)

比如:

var target = { one: 'patridge', three: {a: "1"} },
    source = { two: 'turtle doves' , forth: {b: "2"}, three: {c: "3"} }

$.extend(target, source)

结果:

(2)深层复制

$.extend(true,target, source)

比如:

var target = { one: 'patridge', three: {a: "1"} },
    source = { two: 'turtle doves' , forth: {b: "2"}, three: {c: "3"} }

$.extend(true,target, source)

结果:

2、$.isPlainObject   (v1.0+)

该方法用于判断是否是新创建的对象,即使用{}或者new Object创建的返回true,其余返回false.

3、$.grep、$.map和$.each

(1)$.grep(elements, function(value,index){})

该方法可以过滤子集,返回的还是原来的函数,该方法的function中没有this对象

使用环境:在选取数组的子集时很有用

(2)$.map(elements, function(value,index){})

该方法返回的是新的函数,该方法的function中没有this对象

使用环境:在更改数组中的所有原始值时很有用

(3)$.each(elements, function(index,value){})

该方法返回的是原来的函数,该方法的function中有this对象

使用环境:在数组中的每个元素都调用别的函数时很有用

原文地址:https://www.cnblogs.com/qzccl/p/6100226.html