zhiqingstudy

Be a young person with knowledge and content

Instance member: the object created through the constructor is called an instance object, and the properties and methods in the instance object are called instance members (instance properties and instance methods)

explain:

1. Pass in parameters for the constructor, and create objects with the same structure but different values

2. The instance objects created by the constructor are independent of each other and do not affect each other

        function Person(name){
            this.name=name
            this.sayHi=()=>{// 实例方法
                console.log('Hi 我是'+name)
            }
        }
        const P1=new Person('小明')// P1为实例对象
        console.log(P1.name)// 查看实例属性
        console.log(P1.sayHi())// 调用实例方法

Static members: the properties and methods of the constructor are called static members (static properties and methods)

explain:

1. Static members can only be accessed by constructors

2. This in the static method points to the constructor

        Person.eyes=2 // 添加静态属性
        console.log(Person.sayHi)
        console.log(P1.eyes)
comment
head sculpture
Code:
Related

The art of interpersonal communication and communication

A code of conduct that regulates and regulates interpersonal relationships

The importance of interpersonal relationships




Unless otherwise specified, all content on this website is original. If the reprinted content infringes on your rights, please contact the administrator to delete it
Contact Email:2380712278@qq.com

Filing number:皖ICP备19012824号