variant 1
:'
new object()
'->object constructor without arguments.
var p1=new object();/'new object()'创建并返回空对象->
var p2=new object();/'new object()'创建并返回空对象->
console.log(p1);//空对象->
console.log(p2);//空对象->
//p1和p2是指向不同对象的指针
console.log(p1==p2);//false
console.log(p1.prototype);//未定义
//实际上是object.prototype的空对象
console.log(p1.uu proto_uuu);/
//空对象,p1.\u proto\uuuuu指向该对象
console.log(object.prototype);/
console.log(p1.uu proto_uu==object.prototype);//true
//空,实际上是object.prototype.\u prototo__
console.log(p1.uu proto_uuu.u proto_uuu);//空
console.log(object.prototype.uu proto_uuu);//空
< /代码>

变型2:'new object(person)'->object constructor with argument.
const person={
name:'没有名字',
lastname:'没有姓氏',
年龄:1岁
}
//“new object(person)”返回“person”,它是指向对象的指针->
//->姓名:'no name',姓:'no lastname',年龄:-1
var p1=新对象(人);
//“new object(person)”返回“person”,它是指向对象的指针->
//->姓名:'no name',姓:'no lastname',年龄:-1
var p2=新对象(人);
//person、p1和p2是指向同一对象的指针
console.log(p1==p2);//真
console.log(p1==person);//真
console.log(p2==person);//真
p1.name='john';//将'name'更改为'p1'
p2.lastname='doe';//将'lastname'更改为'p2'
person.age=25;//按“person”更改“age”
//打印“p1”、“p2”和“person”时,结果相同,
//因为它们所指向的对象是相同的
console.log(p1);/name:'john',lastname:'doe',age:25
console.log(p2);/name:'john',lastname:'doe',age:25_
console.log(person);/name:'john',lastname:'doe',age:25
< /代码>

variant 3.1:'object.create(person)'。使用object.create和简单对象“person”。对象。create(person)'将创建(并返回)新的空对象,并将属性“uu proto_uuuuuu”添加到同一个新的空对象。此属性“proto”将指向对象“person”。
const person={
name:'没有名字',
lastname:'没有姓氏',
年龄:1岁,
getinfo:函数getname()。{
返回`$this.name$this.lastname,$this.age!;
}
}
var p1=object.create(人);
var p2=对象.创建(人);
//“p1.\u proto\uuuuuu”和“p2.\u proto\uuuuu”指向
//同一对象->'个人'
//name:'no name',lastname:'no lastname',age:-1,getinfo:[函数:getname]
console.log(p1.协议);
console.log(p2.协议);
console.log(p1.uu proto_uu==p2.u proto_uuuu);//真
console.log(person.uu proto_uuu);/(即object.prototype)
//“person”、“p1”和“p2”不同
console.log(p1==person);//false
console.log(p1==p2);//false
console.log(p2==person);//false
//name:'no name',lastname:'no lastname',age:-1,getinfo:[函数:getname]
主控台日志(人);
console.log(p1);//空对象-
console.log(p2);//空对象-
//向对象“p1”添加属性
//(与对象“person”中同名的属性)
p1.name='john';
p1.lastname='doe';
P1年龄=25;
//向对象“p2”添加属性
//(与对象“person”中同名的属性)
p2.name='汤姆';
p2.lastname='哈里森';
年龄=38岁;
//name:'no name',lastname:'no lastname',age:-1,getinfo:[函数:getname]
主控台日志(人);
//姓名:'John',姓:'Doe',年龄:25
控制台日志(p1);
//姓名:'Tom',姓:'Harrison',年龄:38
控制台日志(p2);
//由“uuu proto_uuuu”(从“p1”到“person”的链接)使用,
//人员的函数“getinfo”
console.log(p1.getinfo());//john doe,25!
//由“uuu proto_uuuu”(从“p2”到“person”的链接)使用,
//人员的函数“getinfo”
console.log(p2.getinfo());//汤姆·哈里森,38岁!
< /代码>

variant 3.2:'object.create(object.prototype)'。使用object.create和内置对象->'object.prototype''。object.create(object.prototype)将创建(并返回)新的空对象,并将属性“uu proto_uuuuuuuu”添加到同一个新的空对象。此属性“proto”将指向对象“object.prototype”。
/'object.create(object.prototype)':
/ / 1。创建并返回空对象->。
/ / 2。添加到“p1”属性“uu proto_uuuuu”,该属性链接到“object.prototype”
var p1=object.create(object.prototype);
//“object.create(object.prototype)”:
/ / 1。创建并返回空对象->。
/ / 2。添加到“p2”属性“proto”中,链接到“object.prototype”
var p2=object.create(object.prototype);
console.log(p1);/
console.log(p2);/
console.log(p1==p2);//false
console.log(p1.prototype);//未定义
console.log(p2.prototype);//未定义
console.log(p1.uu proto_uu==object.prototype);//true
console.log(p2.uu proto_uu==object.prototype);//true
< /代码>

variant 4:'new somefunction()',
构造函数函数“person”中的“this”
//表示新实例,
//将由“new person(…)”创建
//并隐式返回
职能人员(姓名、姓氏、年龄){
this.name=名称;
this.lastname=姓;
这个年龄=年龄;
//————————————————————————————————————————————————————————————————————————————————————————————————————————————————--
/ /!---仅用于演示---
//如果将函数“getinfo”添加到
//构造函数函数“person”,
//那么所有实例都将有一个“getinfo”函数的副本!
/ /
//this.getinfo:函数getinfo()。{
//返回this.name+“”+this.lastname+“,”+this.age+“!”;
//}
//————————————————————————————————————————————————————————————————————————————————————————————————————————————————--
}
//“person.prototype”是空对象
//(在添加函数“getinfo”之前)
console.log(person.prototype);//人
//将“getinfo”添加到“person.prototype”,
//实例的属性“uu proto_uuuu”,
//将可以访问函数“getinfo”。
//使用这种方法,实例不需要
//每个实例的函数“getinfo”的副本。
person.prototype.getinfo=函数getinfo()。{
返回this.name+“”+this.lastname+“,”+this.age+“!”;
}
//函数“getinfo”添加到“person.prototype”后
console.log(person.prototype);//person getinfo:[函数:getinfo]
//创建实例“p1”
var p1=新人(“John”,“Doe”,25);
//创建实例“p2”
var p2=新人(“汤姆”,“哈里森”,38);
//人名:'john',姓:'doe',年龄:25
控制台日志(p1);
//人名:'Tom',姓:'Harrison',年龄:38
控制台日志(p2);
//“p1.\u proto\uuuuuuu”指向“person.prototype”
console.log(p1.uuu proto_uuu);//person getinfo:[函数:getinfo]
//“p2.\u proto\uuuuuuu”指向“person.prototype”
console.log(p2.uuu proto_uuuu);//person getinfo:[函数:getinfo]
console.log(p1.uu proto_uu==p2.u proto_uuuu);//真
//“p1”和“p2”指向不同的对象(“person”的实例)
console.log(p1==p2);//false
//“p1”通过其属性“uuu proto_uuuuuuuuuuu”到达“person.prototype.getinfo”
//并将“getinfo”与“p1”-实例的数据一起使用
console.log(p1.getinfo());//john doe,25!
//“p2”通过其属性“uuu proto_uuuuuuuuuuuu”到达“person.prototype.getinfo”
//并将“getinfo”与“p2”-实例的数据一起使用
console.log(p2.getinfo());//汤姆·哈里森,38岁!
< /代码>

R没有参数。
var p1 = new Object(); // 'new Object()' create and return empty object -> {}
var p2 = new Object(); // 'new Object()' create and return empty object -> {}
console.log(p1); // empty object -> {}
console.log(p2); // empty object -> {}
// p1 and p2 are pointers to different objects
console.log(p1 === p2); // false
console.log(p1.prototype); // undefined
// empty object which is in fact Object.prototype
console.log(p1.__proto__); // {}
// empty object to which p1.__proto__ points
console.log(Object.prototype); // {}
console.log(p1.__proto__ === Object.prototype); // true
// null, which is in fact Object.prototype.__proto__
console.log(p1.__proto__.__proto__); // null
console.log(Object.prototype.__proto__); // null

变型2:新对象(人)'->带参数的对象构造函数。
const person = {
name: 'no name',
lastName: 'no lastName',
age: -1
}
// 'new Object(person)' return 'person', which is pointer to the object ->
// -> { name: 'no name', lastName: 'no lastName', age: -1 }
var p1 = new Object(person);
// 'new Object(person)' return 'person', which is pointer to the object ->
// -> { name: 'no name', lastName: 'no lastName', age: -1 }
var p2 = new Object(person);
// person, p1 and p2 are pointers to the same object
console.log(p1 === p2); // true
console.log(p1 === person); // true
console.log(p2 === person); // true
p1.name = 'John'; // change 'name' by 'p1'
p2.lastName = 'Doe'; // change 'lastName' by 'p2'
person.age = 25; // change 'age' by 'person'
// when print 'p1', 'p2' and 'person', it's the same result,
// because the object they points is the same
console.log(p1); // { name: 'John', lastName: 'Doe', age: 25 }
console.log(p2); // { name: 'John', lastName: 'Doe', age: 25 }
console.log(person); // { name: 'John', lastName: 'Doe', age: 25 }

变型3.1:对象.创建(人)'.使用object.create和简单对象“person”。对象。create(person)'将创建(并返回)新的空对象,并将属性“uu proto_uuuuuu”添加到同一个新的空对象。此属性“proto”将指向对象“person”。
const person = {
name: 'no name',
lastName: 'no lastName',
age: -1,
getInfo: function getName() {
return `${this.name} ${this.lastName}, ${this.age}!`;
}
}
var p1 = Object.create(person);
var p2 = Object.create(person);
// 'p1.__proto__' and 'p2.__proto__' points to
// the same object -> 'person'
// { name: 'no name', lastName: 'no lastName', age: -1, getInfo: [Function: getName] }
console.log(p1.__proto__);
console.log(p2.__proto__);
console.log(p1.__proto__ === p2.__proto__); // true
console.log(person.__proto__); // {}(which is the Object.prototype)
// 'person', 'p1' and 'p2' are different
console.log(p1 === person); // false
console.log(p1 === p2); // false
console.log(p2 === person); // false
// { name: 'no name', lastName: 'no lastName', age: -1, getInfo: [Function: getName] }
console.log(person);
console.log(p1); // empty object - {}
console.log(p2); // empty object - {}
// add properties to object 'p1'
// (properties with the same names like in object 'person')
p1.name = 'John';
p1.lastName = 'Doe';
p1.age = 25;
// add properties to object 'p2'
// (properties with the same names like in object 'person')
p2.name = 'Tom';
p2.lastName = 'Harrison';
p2.age = 38;
// { name: 'no name', lastName: 'no lastName', age: -1, getInfo: [Function: getName] }
console.log(person);
// { name: 'John', lastName: 'Doe', age: 25 }
console.log(p1);
// { name: 'Tom', lastName: 'Harrison', age: 38 }
console.log(p2);
// use by '__proto__'(link from 'p1' to 'person'),
// person's function 'getInfo'
console.log(p1.getInfo()); // John Doe, 25!
// use by '__proto__'(link from 'p2' to 'person'),
// person's function 'getInfo'
console.log(p2.getInfo()); // Tom Harrison, 38!

变型3.2:对象.创建(对象.原型)'.使用object.create和内置对象->'object.prototype''。object.create(object.prototype)将创建(并返回)新的空对象,并将属性“uu proto_uuuuuuuu”添加到同一个新的空对象。此属性“proto”将指向对象“object.prototype”。
// 'Object.create(Object.prototype)' :
// 1. create and return empty object -> {}.
// 2. add to 'p1' property '__proto__', which is link to 'Object.prototype'
var p1 = Object.create(Object.prototype);
// 'Object.create(Object.prototype)' :
// 1. create and return empty object -> {}.
// 2. add to 'p2' property '__proto__', which is link to 'Object.prototype'
var p2 = Object.create(Object.prototype);
console.log(p1); // {}
console.log(p2); // {}
console.log(p1 === p2); // false
console.log(p1.prototype); // undefined
console.log(p2.prototype); // undefined
console.log(p1.__proto__ === Object.prototype); // true
console.log(p2.__proto__ === Object.prototype); // true

变型4:新建someFunction()’
// 'this' in constructor-function 'Person'
// represents a new instace,
// that will be created by 'new Person(...)'
// and returned implicitly
function Person(name, lastName, age) {
this.name = name;
this.lastName = lastName;
this.age = age;
//-----------------------------------------------------------------
// !--- only for demonstration ---
// if add function 'getInfo' into
// constructor-function 'Person',
// then all instances will have a copy of the function 'getInfo'!
//
// this.getInfo: function getInfo() {
// return this.name + " " + this.lastName + ", " + this.age + "!";
// }
//-----------------------------------------------------------------
}
// 'Person.prototype' is an empty object
// (before add function 'getInfo')
console.log(Person.prototype); // Person {}
// With 'getInfo' added to 'Person.prototype',
// instances by their properties '__proto__',
// will have access to the function 'getInfo'.
// With this approach, instances not need
// a copy of the function 'getInfo' for every instance.
Person.prototype.getInfo = function getInfo() {
return this.name + " " + this.lastName + ", " + this.age + "!";
}
// after function 'getInfo' is added to 'Person.prototype'
console.log(Person.prototype); // Person { getInfo: [Function: getInfo] }
// create instance 'p1'
var p1 = new Person('John', 'Doe', 25);
// create instance 'p2'
var p2 = new Person('Tom', 'Harrison', 38);
// Person { name: 'John', lastName: 'Doe', age: 25 }
console.log(p1);
// Person { name: 'Tom', lastName: 'Harrison', age: 38 }
console.log(p2);
// 'p1.__proto__' points to 'Person.prototype'
console.log(p1.__proto__); // Person { getInfo: [Function: getInfo] }
// 'p2.__proto__' points to 'Person.prototype'
console.log(p2.__proto__); // Person { getInfo: [Function: getInfo] }
console.log(p1.__proto__ === p2.__proto__); // true
// 'p1' and 'p2' points to different objects(instaces of 'Person')
console.log(p1 === p2); // false
// 'p1' by its property '__proto__' reaches 'Person.prototype.getInfo'
// and use 'getInfo' with 'p1'-instance's data
console.log(p1.getInfo()); // John Doe, 25!
// 'p2' by its property '__proto__' reaches 'Person.prototype.getInfo'
// and use 'getInfo' with 'p2'-instance's data
console.log(p2.getInfo()); // Tom Harrison, 38!
