What is an object?
A. Abstraction of real things-object- oriented is the abstraction of real things
B. Encapsulation of data-a package of specific data, a collection of properties and methods
Three major features of an object (encapsulation, inheritance, polymorphism)
1. Encapsulation is the encapsulation of properties and methods
2. Inheritance is what others do not have, take over to become their own is inheritance, JS does not have a specific inheritance mechanism, but can be technically practical
3. Polymorphism, the different manifestations of different situations. If a method, pass a parameter and pass multiple parameters, get the result is not the same
# # Four ways to create an object # #
* * 1. Declaration Paradigm * *
var obj = {}
**2. Factory function 1**
function Stu (name,age) {
return {
Name:name,
Age:age,
Sayhello:function () {
Console.log (' I am ' +this.name+ ' this year ' +this.age+ ' years ')
// }
// }
// }
var stu1 = stu (' Zhangsan ', 21)
Stu1.sayhello ()
//
**3. Factory function 2**
function Stu (name,age) {
var obj = {};
Obj.name = name;
Obj.age = age,
Obj.sayhello = function () {
Console.log (' I am ' +this.name+ ' this year ' +this.age+ ' years ')
// }
return obj
// }
var stu1 = stu (' lis ', 22);
Stu1.sayhello ()
//
//
**4. Factory function 3--Constructor, key * *
//function Student (name,age) {
// this.name = name;
// this.age = age;
// this.sayhello = function () {
// Console.log (' I am ' +this.name+ ' this year ' +this.age+ ')
// }
//}
//var stu1 = new Student (' Wang5 ', 1);
//Stu1.sayhello ()
Object concept--javascript Object-oriented advanced