js预编译

<!DOCTYPE html>
<html>

<body>
    <script>
        /**
         * 1 通过定义并创建对象的实例
         */
        var person = {}
        var person = new Object();
        /**
         * 2:通过构造函数来创建对象
         * 构造函数和普通函数没有区别,但是为了区分,一般都会采用大驼峰方式命名。
         * 生成对象的时候通过new关键字来执行
         * 原理: a:首先在构造函数第一行 var this = {}
         *      b:通过 this.name = "xiaofu"等进行赋值
         *      c:在构造函数的最后 return this;
         */
        function Person() {
            // a:  var this = {}
            // b: this.name = "xiaofu"等进行赋值
            this.name = "xiaofu";
            this.weight = "60kg",
                this.skill = function() {
                    console.log("I can run");
                }
                // c: return this;
        }
        var personFU = new Person();


        // 用自定义构造函数的方式创建对象
        function Car(name, color, weight) {
            var that = {};
            that.name = name;
            that.color = color;
            that.weight = weight;
            return that;
        }
        var car1 = Car();
    </script>

</body>

</html>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值