function CreateFn(name,age) {
this.name = name;
this.age = age;
this.getName = function() {
console.log(this.name)
}
}
var fn1 = new CreateFn("小明",26);
var fn2 = new CreateFn("小明",26);
fn1.getName()
console.log(fn1.age)
console.log(fn1.getName == fn2.getName); // false
PS: 1 其实构造函数 就是普通函数 ,只不过 函数名首字母大写 !
2 函数内部定义的变量不是 var str = ‘xxx’ 了, 而是 this.str ,
this 指当前对象 !