new关键字执行过程

new关键字执行过程

    <script>
        // new关键字执行过程
        // 1.new构造函数可以在内存中创建一个空的对象
        // 2.this就会指向刚才创建的空对象
        // 3.执行构造函数里的代码 给这个空对象添加属性和方法
        function Star(uname, age, sex){
            this.name = uname;
            this.age = age;
            this.sex = sex;
            this.sing = function(sang){
                console.log(sang);
            }
        }
        var ldh = new Star('刘德华', 18, '男');
    </script>

你可能感兴趣的:(new关键字执行过程)