您当前的位置: 首页 >  jquery

wespten

暂无认证

  • 0浏览

    0关注

    899博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

深入学习jquery源码之jQuery中高质量的代码

wespten 发布时间:2018-12-29 06:28:08 ,浏览量:0

深入学习jquery源码之jQuery中高质量的代码

1、this指向的问题 

function Student(name,age,grade,school){    
    Person.apply(this,arguments);           
}

他就具备了Person类的sayhello方法和所有属性。通过实例可以调用了

 

2、返回数组(其他元素转为数组元素)

function (num) {
 return num != null ?
 // Return just the one element from the set
 (num < 0 ? this[num + this.length] : this[num]) :
 // Return all the elements in a clean array
 [].slice.call(this)
}
或者是
Array.prototype.slice.call(arguments)

 

3、数组的合并包含重复的元素

( [0,1,2], [2,3,4] ) // [0,1,2,2,3,4]
function (first, second) {
            var len = +second.length,
                j = 0,
                i = first.length;

            while (j < len) {
                first[i++] = second[j++];
            }

            // Support: IE{
  guigeArr.forEach((v,i)=>{
    if(!newArr[i].includes(v))
      newArr[i].push(v)
  })
})

console.log(newArr)
// [["蓝色", "黑色"], ["XL", "L"], ["3", "6"], ["S"]]

 

11、js弱类型语言 对象的属性确实可以通过类似于通过访问数组的中括号形式进行访问。 在js里,对象就是普通的键值对存取数据,Array类型的数据都是一维的,通过索引来存取数据,数字下标的数据集合。

var obj = {
 name:'lily',
 year:'20'
 
}
//用属性值获取
alert(obj.year);
// 用变量获取
alert(obj[y]);

定义对象

var i = 1,target = arguments[0] || {};
if ((options = arguments[i]) != null) {
// Extend the base object
for (name in options) {
target[name] = copy;
}
}

对象和数组的遍历

var arr = [1,2,3,4,5,6]
var stu = {
    name : "张三",
    sex : "男",
    age : 18,
    address : "四川成都",
}

        for (var i in arr) {
            console.log(i, arr[i]);
                    //输出
                    //0 1
                    //1 2
                    //2 3
                    //3 4
                    //4 5
                    //5 6
        }
        for (var i in stu) {
            console.log(i, stu[i]);
                    //输出
                    //name 张三
                    //sex 男
                    //age 18
                    //address 四川成都
        }

 

关注
打赏
1665965058
查看更多评论
立即登录/注册

微信扫码登录

0.0409s