十二、构造函数的四步

十二、构造函数的四步

  1. 开辟了一个新的内存空间
  2. 与this绑定
  3. 执行函数中的代码
  4. 返回this
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// 定义构造函数
function People(name, age, sex){
// console.log(this);
this.name = name;
this.age = age;
this.sex = sex;

//return是值类型的时候 则忽略
// return 1;
// return "";
// return true;
// return null;
// return undefined;

//return是引用类型的时候 以return为准
// return {};
// return [];

// 所以,在构造函数中不要使用return
}

// 初始化对象
var xiaoming = new People("小明", 12, "男");
console.log(xiaoming);
点击查看

本文标题:十二、构造函数的四步

文章作者:Mango

发布时间:2020年07月13日 - 23:20:23

最后更新:2020年07月14日 - 13:27:10

原始链接:https://mango185.github.io/post/23ea5654.html

许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。

-------------------本文结束 感谢您的阅读-------------------