1、构造函数不具备预解析功能
var p1 = new Person();
console.log( p1.showName() ); //会报错的
function Person(){
this.name = 'xiaoming';
}
Person.prototype.showName = function(){
return '我叫:' + this.name;
}
/* 注意的点:当写面向对象程序的时候,一定要把类或构造函数定义在前面,创建对象在后面去做,这样才不会出现问题。 */
2、箭头函数不能当构造函数去使用
//箭头函数不能当构造函数去使用
var Person = ()=>{
this.name = 'xiaoming';
this.showName = function(){
return '我叫:' + this.name;
}
}
var p1 = new Person(); //会报错的
console.log( p1.showName() );