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)