码迷,mamicode.com
首页 > 其他好文 > 详细

前端面向对象理解

时间:2020-05-31 22:04:29      阅读:70      评论:0      收藏:0      [点我收藏+]

标签:面向   面向对象   turn   第一步   log   script   创建   charset   show   

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>面向对象</title>
</head>
<body>
<script>
    function Cat() { //Cat 猫
        //this = {} 让this指向一个空对象
        // var t ={};
        // this = t;
        // t.__proto__ =Cat.prototype

        this.age=18
        this.show=function () {
            console.log(this.age)
        }
        // return this
    }
    Cat.prototype.name=‘hangsan‘
    var cat = new Cat(); //通过构造函数创建一个对象出来
    // cat.show()
    /*new:内部原理
        第0步:在内存中开辟一块空间
        第一步:创建一个新的空对象
        第二步:让this指向这个空对象
        第三步:把空对象的内部原型指向构造函数的原型对象
        第四步:当构造函数执行完后,如果有return的话,那么把当前的空对象返回*/
    // console.log(Cat.prototype==cat.__proto__)

</script>
</body>
</html>

  

前端面向对象理解

标签:面向   面向对象   turn   第一步   log   script   创建   charset   show   

原文地址:https://www.cnblogs.com/malong1992/p/13021520.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!