一、

键值对生成

var obj1 = {
                name: '对象',
                age: 18,
                sayHi: function(){
                    console.log('hi~');
                }
            }
            console.log(obj1.name);
            obj1.sayHi();

二、

等号赋值

var obj2 = new Object;
            obj2.name = '对象2';
            obj2.age = 19;
            obj2.sayHi = function(){
                console.log('hello');
            }
            console.log(obj2.name);
            obj2.sayHi();

三、

构造函数

    function Obj(name, age) {
                this.name = name;
                this.age = age;
                this.sayHi = function(hi){
                    console.log(hi);
                };
            };
            var obj3= new Obj('对象3',20);
            console.log(obj3.name);
            obj3.sayHi('hei');

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

评论(2)

  • 泽泽 2021年 9月 18日 上午9:08

    这种对象能用吗 ::aru:speechless::

    • cyril 普通 @ 泽泽 2021年 9月 21日 下午9:11

      我也不知道啊,网上看到的,就发出来了。大佬都用什么