<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<script>
function Person(myName,myAge)
{
// let obj=new Object();//系统做的事情
// let this=obj;//系统做的事情
this.name=myName;
this.age=myAge;
this.say=function()
{
console.log("hello world");
}
// return this;//系统做的事情
}
let obj1=new Person("cyg",20);
let obj2=new Person("lw",20);
//问题来了,系统在创建对象的过程中到底做了什么?
//会在构造函数中自动创建一个对象
//为什么?因为告诉构造函数这是一个对象.
//会把对象赋值给this
//为什么,因为this得有作用啊
//会在构造函数最后添加return this;
不返回给obj1怎么继续做事情
///构造函数首字母得大写
</script>
</body>
</html>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<script>
function Person(myName,myAge)
{
// let obj=new Object();//系统做的事情
// let this=obj;//系统做的事情
this.name=myName;
this.age=myAge;
this.say=function()
{
console.log("hello world");
}
// return this;//系统做的事情
}
let obj1=new Person("cyg",20);
let obj2=new Person("lw",20);
console.log(obj1.say===obj2.say);//内存地址是否一样
//问题来了,系统在创建对象的过程中到底做了什么?
//会在构造函数中自动创建一个对象
//为什么?因为告诉构造函数这是一个对象.
//会把对象赋值给this
//为什么,因为this得有作用啊
//会在构造函数最后添加return this;
不返回给obj1怎么继续做事情
///构造函数首字母得大写
function demo()
{
console.log("demo");
}
console.log(demo===demo);//内存地址一样,对象地址不一样
</script>
</body>
</html>