jQ原理

1、oop三大特征:
   封装:将一堆方法和属性放在一起。目的:将信息隐藏
   继承:最大限度重用代码。目的:找到共性,精简代码,提高重用性
   多态:不同类的同名方法。目的:使语言具有动态性,具有更好的通用性
2、构造函数、析构函数
   构造函数:开辟内存空间
   析构函数:释放内存空间
3、原型:该类的公共存储空间,用于节省内存
4、原型链:当访问对象的某个属性或方法时,先在自己的构造函数中寻找,如果没有,就在自己的原型中寻找,如果还没有,就找原型的原型,一直向上寻找一直找到object的原型,这样形成的一个链条称之为原型链
5、MVC是什么:
   是一种设计理念,将代码进行逻辑分离,分离成控制层、视图层及数据层三层
6、MVC有什么作用:
   降低了耦合度,提高了代码的扩展性,易修改性
7、为了避免内存浪费,不建议方法写在构造函数
   this.sale = function(){
      console.log(‘全场8折’); //封装 把属性和方法放在一起
   }
8、建议:方法及公共属性写在原型中
   原需要用构造函数名调用,实例对象不能调用
   原型的本质是个对象_proto_
9、object指向null
10、反转字符串:
   function reverseString(string){
      return string.split(‘’).reverse().join(‘’);
   }
11、继承:
   我们使用call和apply方式实现构造函数的聚成
   call与apply的作用:改变this指向
12、原型继承:
   B.prototype = A.prototype
   这里有引用问题
   修改A就会修改B,修改B就会修改A
   推荐:
   for(var x in A.prototype){
      B.prototype[x] = A.prototype[x];
   }

微信朋友圈:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>微信朋友圈</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            list-style: none;
        }
        html {
            font-size: 62.5%;
        }
        .container {
            width: 320px;
            height: 568px;
            box-shadow: 1px 1px 3px gray;
            margin: 0 auto;
            overflow: scroll;
        }
        ul {
            background-color: #e5e5e5;
        }
        li {
            background-color: #fff;
            margin-bottom: 1px;
            font-size: 1.6rem;
        }
        li>img {
            width: 56px;
            height: 56px;
            border-radius: 4px;
            float: left;
            margin: 10px;
        }
        li>div {
            width: 236px;
            float: left;
            margin-top: 10px;
        }
        li>div .nick {
            color: #546589;
        }
        li>div .words {
            line-height: 20px;
        }
        li>div .pics {
            overflow: hidden;
        }
        li>div .pics img {
            width: 75px;
            height: 75px;
            float: left;
            margin-right: 1px;
            margin-top: 1px;
        }
        li>div .link {
            display: block;
            height: 50px;
            background-color: lightgrey;
            margin: 10px 0;
        }
        li>div .link img {
            float: left;
            width: 50px;
            height: 50px;
        }
        li>div .link p {
            float: left;
            width: 180px;
            overflow: hidden;
            line-height: 50px;
            margin-left: 3px;
            color: black;
        }
        li>div .videoImg {
            display: block;
            width: 220px;
            height: 160px;
            margin: 10px 0;
        }
        li>div .adLink {
            display: block;
            width: 180px;
            height: 200px;
            margin: 10px 0;
        }
        li>div .adLink img {
            display: block;
            width: 100%;
            height: 100%;
        }
    </style>
</head>
<body>
    <div class="container">
        <ul>
        </ul>
    </div>
</body>
<script src="js/data.js"></script>
<script src="js/model.js"></script>
<script src="js/view.js"></script>
<script>
    data.forEach(function(obj){  //只有纯数组可以用,类数组不可以用
        var model = createModel(obj);
        var view = createView(model);
        document.querySelector('ul').appendChild(view);
    })
</script>
</html>

/*
    type:
    *info  图文类型
    *video 视频类型
    *ad    广告类型
    *link  链接类型
*/

var data = [
    {
        head_pic: "https://t7.baidu.com/it/u=4162611394,4275913936&fm=193&f=GIF",
        nick: "hey,熊猫先生",
        words: "大郎,该吃药了!",
        type: "info",
        time: "1小时前",
        pics: [
            "https://t7.baidu.com/it/u=2582370511,530426427&fm=193&f=GIF",
            "https://t7.baidu.com/it/u=2851687453,2321283050&fm=193&f=GIF",
            "https://t7.baidu.com/it/u=3601447414,1764260638&fm=193&f=GIF",
            "https://t7.baidu.com/it/u=4069854689,43753836&fm=193&f=GIF",
            "https://t7.baidu.com/it/u=2141219545,3103086273&fm=193&f=GIF",
            "https://t7.baidu.com/it/u=3601447414,1764260638&fm=193&f=GIF",
            "https://t7.baidu.com/it/u=3332251293,4211134448&fm=193&f=GIF",
            "https://t7.baidu.com/it/u=1035726655,1110652804&fm=193&f=GIF",
            "https://t7.baidu.com/it/u=762481686,2214126081&fm=193&f=GIF"
        ]
    },{
        head_pic: "https://t7.baidu.com/it/u=4162611394,4275913936&fm=193&f=GIF",
        nick: "路人甲",
        words: "今天好像看到策哥了!",
        type: "video",
        time: "1小时前",
        video_url: "https://t7.baidu.com/it/u=4080826490,615918710&fm=193&f=GIF"
    },{
        head_pic: "https://t7.baidu.com/it/u=4162611394,4275913936&fm=193&f=GIF",
        nick: "hey,熊猫先生",
        words: "大郎,该吃药了!",
        type: "info",
        time: "1小时前",
        pics: [
            "https://t7.baidu.com/it/u=2582370511,530426427&fm=193&f=GIF",
            "https://t7.baidu.com/it/u=2851687453,2321283050&fm=193&f=GIF",
            "https://t7.baidu.com/it/u=3601447414,1764260638&fm=193&f=GIF",
            "https://t7.baidu.com/it/u=4069854689,43753836&fm=193&f=GIF",
            "https://t7.baidu.com/it/u=2141219545,3103086273&fm=193&f=GIF",
            "https://t7.baidu.com/it/u=3601447414,1764260638&fm=193&f=GIF"
        ]
    },{
        head_pic: "https://t7.baidu.com/it/u=4162611394,4275913936&fm=193&f=GIF",
        nick: "hey,熊猫先生",
        words: "大郎,该吃药了!",
        type: "info",
        time: "1小时前",
        pics: [
            "https://t7.baidu.com/it/u=2582370511,530426427&fm=193&f=GIF",
            "https://t7.baidu.com/it/u=2851687453,2321283050&fm=193&f=GIF"
        ]
    },{
        head_pic: "https://t7.baidu.com/it/u=334080491,3307726294&fm=193&f=GIF",
        nick: "路人已",
        words: "今天好像看到策哥了!",
        type: "ad",
        time: "1小时前",
        ad_pic: "https://t7.baidu.com/it/u=3713375227,571533122&fm=193&f=GIF",
        link: "http://www.baidu.com"
    },{
        head_pic: "https://t7.baidu.com/it/u=2235903830,1856743055&fm=193&f=GIF",
        nick: "路人并",
        words: "今天好像看到策哥了!",
        type: "link",
        time: "1小时前",
        linkInfo: {
            pic: "https://t7.baidu.com/it/u=801209673,1770377204&fm=193&f=GIF",
            content: "这是个链接",
            url: "http://www.jd.com"
        }
    },{
        head_pic: "https://t7.baidu.com/it/u=334080491,3307726294&fm=193&f=GIF",
        nick: "路人已",
        words: "今天好像看到策哥了!",
        type: "ad",
        time: "1小时前",
        ad_pic: "https://t7.baidu.com/it/u=3713375227,571533122&fm=193&f=GIF",
        link: "http://www.baidu.com"
    },{
        head_pic: "https://t7.baidu.com/it/u=2235903830,1856743055&fm=193&f=GIF",
        nick: "路人并",
        words: "今天好像看到策哥了!",
        type: "link",
        time: "1小时前",
        linkInfo: {
            pic: "https://t7.baidu.com/it/u=801209673,1770377204&fm=193&f=GIF",
            content: "这是个链接",
            url: "http://www.jd.com"
        }
    },{
        head_pic: "https://t7.baidu.com/it/u=4162611394,4275913936&fm=193&f=GIF",
        nick: "hey,熊猫先生",
        words: "大郎,该吃药了!",
        type: "info",
        time: "1小时前",
        pics: [
            "https://t7.baidu.com/it/u=2582370511,530426427&fm=193&f=GIF",
            "https://t7.baidu.com/it/u=2851687453,2321283050&fm=193&f=GIF",
            "https://t7.baidu.com/it/u=3601447414,1764260638&fm=193&f=GIF",
            "https://t7.baidu.com/it/u=4069854689,43753836&fm=193&f=GIF",
            "https://t7.baidu.com/it/u=2141219545,3103086273&fm=193&f=GIF",
            "https://t7.baidu.com/it/u=3601447414,1764260638&fm=193&f=GIF"
        ]
    },{
        head_pic: "https://t7.baidu.com/it/u=4162611394,4275913936&fm=193&f=GIF",
        nick: "路人甲",
        words: "今天好像看到策哥了!",
        type: "video",
        time: "1小时前",
        video_url: "https://t7.baidu.com/it/u=4080826490,615918710&fm=193&f=GIF"
    }
];
function Model(obj){
    this.head_pic = obj.head_pic;
    this.nick = obj.nick;
    this.time = obj.time;
    this.type = obj.type;
    this.words = obj.words;
}

// 子类
function InfoModel(obj){
    Model.call(this,obj);
    this.pics = obj.pics;
}
function AdModel(obj){
    Model.call(this,obj);
    this.ad_pic = obj.ad_pic;
    this.link = obj.link;
}
function VideoModel(obj){
    Model.call(this,obj);
    this.video_url = obj.video_url;
}
function LinkModel(obj){
    Model.call(this,obj);
    this.linkInfo = obj.linkInfo;
}

// 外部调用
function createModel(obj){
    var model = null;
    if(obj.type === "ad"){
        model = new AdModel(obj);
    } else if (obj.type === "link"){
        model = new LinkModel(obj);
    } else if (obj.type === "video"){
        model = new VideoModel(obj);
    } else if (obj.type === "info"){
        model = new InfoModel(obj);
    }
    return model;
}
// 创建不同类型的视图
function infoView(model){
    var d = document.createElement('li');
    d.innerHTML = `
    <img src="${model.head_pic}" alt="">
    <div>
        <p class="nick">${model.nick}</p>
        <p class="words">${model.words}</p>
        <div class="pics">
        
        </div>
        <p class="time">${model.time}</p>
    </div>
    `;
    // 根据数据的内容动态添加img
    var pics = d.querySelector(".pics");
    model.pics.forEach(function(url){
        pics.innerHTML += `
            <img src="${url}" />
        `
    })
    return d;
}
function adView(model){
    var d = document.createElement('li');
    d.innerHTML = `
    <img src="${model.head_pic}" alt="">
    <div>
        <p class="nick">${model.nick}</p>
        <p class="words">${model.words}</p>
        <a class="adLink" href="${model.link}">
            <img src="${model.ad_pic}" alt="">
        </a>
        <p class="time">${model.time}</p>
    </div>
    `;
    return d;
}
function linkView(model){
    var d = document.createElement('li');
    d.innerHTML = `
    <img src="${model.head_pic}" alt="">
    <div>
        <p class="nick">${model.nick}</p>
        <p class="words">${model.words}</p>
        <a href="${model.linkInfo.url}" class="link">
            <img src="${model.linkInfo.pic}" alt="">
            <p>${model.linkInfo.content}</p>
        </a>
        <p class="time">${model.time}</p>
    </div>
    `;
    return d;
}
function videoView(model){
    var d = document.createElement('li');
    d.innerHTML = `
    <img src="${model.head_pic}" alt="">
                <div>
                    <p class="nick">${model.nick}</p>
                    <p class="words">${model.words}</p>
                    <img class="videoImg" src="${model.video_url}" alt="">
                    <p class="time">${model.time}</p>
                </div>
    `;
    return d;
}


// 对外调用
function createView(model){
    var li = null;
    if(model.type === "ad"){
        view = adView(model);
    } else if (model.type === "link"){
        view = linkView(model);
    } else if (model.type === "video"){
        view = videoView(model);
    } else if (model.type === "info"){
        view = infoView(model);
    }
    return view;
}
jquery技术内幕:深入解析jquery架构设计与实现原理》由阿里巴巴资深前端开发工程师撰写,从源代码角度全面而系统地解读了jquery的17个模块的架构设计理念和内部实现原理,旨在帮助读者参透jquery中的实现技巧和技术精髓,同时本书也对广大开发者如何通过阅读源代码来提升编码能力和软件架构能力提供了指导。   《jquery技术内幕:深入解析jquery架构设计与实现原理》首先通过“总体架构”梳理了各个模块的分类、功能和依赖关系,让大家对jquery的工作原理有大致的印象;进而通过“构造jquery对象”章节分析了构造函数jquery()的各种用法和内部构造过程;接着详细分析了底层支持模块的源码实现,包括:选择器sizzle、异步队列deferred、数据缓存data、队列queue、浏览器功能测试support;最后详细分析了功能模块的源码实现,包括:属性操作attributes、事件系统events、dom遍历traversing、dom操作manipulation、样式操作css、异步请求ajax、动画effects。   《jquery技术内幕:深入解析jquery架构设计与实现原理》在分析每个模块时均采用由浅入深的方式,先概述功能、用法、结构和实现原理,然后介绍关键步骤和分析源码实现。让读者不仅知其然,而且知其所以然。事实上,本书的根本价值在于传达一种通过阅读源码快速成长的方式。无论是前端新人,还是经验丰富的老手,只要是对javascript感兴趣的开发人员,都会从本书中受益。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值