/*
*构造函数首字母大写
*钩爪函数不需要return,直接返回一个结果
*/
function Man (name, age, gender) {
this.name = name;
this.age = age;
this.gender = gender;
this.doing = function (action){
console.log(name+'正在'+action)
}
}
const xiaoli = new Man('xiaoli', 20, '男')
console.log(typeof(xiaoli))
console.log(xiaoli)
console.log(xiaoli['gender'])
xiaoli.doing('吃饭')
类比后端方法中的类,js中的构造函数相当与后端方法中的类
构造函数和对象的关系:对象可以从构造函数的实例化
上面代码中的xiaoli对象就是构造函数Man的实例化对象