//js定义对象的几种容易犯的错误
function Person() {
getName = function (){
console.info(1);
};
return this;
}
//Person.getName();//提示错误:这不是一个函数
Person.getName = function () {
console.log('Person.getName');
}
Person.prototype.username = "zhangsan";
Person.prototype.password = "0123";
Person.prototype.getName = function() {
console.info(this.username + ":" + this.password);
}
var person = new Person();
var person2 = new Person();
person.username = "lisi";
Person().getName();//1
Person.getName();//Person.getName
person.getName();// lisi 0123
person2.getName();//zhangsan 0123
new Person.getName();//Person.getName
new new Person().getName(); //undefined
var info = function () {
console.log(3);
}
function info(){
console.log(4);
}
info();//3